Quantcast
Channel: DataTables 1.9 — DataTables forums
Viewing all 1816 articles
Browse latest View live

Use jQuery datatables server-side processing with mvc. Serialize criteria in form

$
0
0
Hi all, i'm using mvc and jquery datatables, with serve side processing.

I have created two Class Model:
the first jQueryParamModel, to pass dataTables parameters to action controller
    public class JQueryDataTableParamModel
    {
        /// <summary>
        /// Request sequence number sent by DataTable, same value must be returned in response
        /// </summary>       
        public string sEcho{ get; set; }

        /// <summary>
        /// Text used for filtering
        /// </summary>
        public string sSearch{ get; set; }

        /// <summary>
        /// Number of records that should be shown in table
        /// </summary>
        public int iDisplayLength{ get; set; }

        /// <summary>
        /// First record that should be shown(used for paging)
        /// </summary>
        public int iDisplayStart{ get; set; }

        /// <summary>
        /// Number of columns in table
        /// </summary>
        public int iColumns{ get; set; }

        /// <summary>
        /// Number of columns that are used in sorting
        /// </summary>
        public int iSortingCols{ get; set; }

        /// <summary>
        /// Comma separated list of column names
        /// </summary>
        public string sColumns{ get; set; }

    }
 

the second rapresent two custom search criteria
    public class Home2Model
    {
        public CriteriaModel SearchCriteria1 { get; set; }
        public CriteriaModel SearchCriteria2 { get; set; }
    }

public class CriteriaModel
    {
        public int? integer { get; set; }
    }
 

After i have created a strongly typed view with Home2Model, named index.cshtml
     @model GenericSearch.UI.Models.Home2Model

    <link href="@Url.Content("~/Content/dataTables/demo_table.css")" rel="stylesheet" type="text/css" />
    <script src="@Url.Content("~/Scripts/jquery.dataTables.min.js")" type="text/javascript"></script>
    <script>
        $(document).ready(function () {
            var oTable = $('#myDataTable').dataTable({
                "bServerSide": true,
                "sAjaxSource": "/Home2/AjaxHandler",
                "bProcessing": false,
                "sServerMethod": "POST",
                "fnServerData": function (sSource, aoData, fnCallback) {

                    aoData.push({ "name": "hm", "value": $("myForm").serialize() });

                    $.ajax({
                        "dataType": 'json',
                        "type": "POST",
                        "url": sSource,
                        "data": aoData,
                        "success": fnCallback
                    })
                }
            });
        });

    </script>

    <h1>Search</h1>
<br />
@using (Html.BeginForm("Index", "Home2", FormMethod.Post, new { id="myForm"}))
{
        <div >
            @Html.EditorFor(m => m.SearchCriteria1)
            @Html.EditorFor(m => m.SearchCriteria2)
            <br />
            <input type="submit" name="default" value="Filter" />
            <br /><br />
            <table id="myDataTable" class="display">
                <thead>
                    <tr>
                        <th>a</th>
                        <th>b</th>
                        <th>c</th>
                        <th>d</th>
                        <th>e</th>
                        <th>f</th>
                    </tr>
                </thead>
                <tbody>
                </tbody>
            </table>
        </div>
}
 


I'have create a contoller action that recive in input this parameters:
    [HttpPost]
        public ActionResult AjaxHandler(JQueryDataTableParamModel param,Home2Model hm)
        {
            return new EmptyResult();
        }
 

JQueryDataTableParamModel bind work properly, but hm param isn't valorized (null). the mvc binding doesn't work correctly.

Can any one help me ?

Thank you in advantage.

Ctrl+A event on datatables

$
0
0
Hi All, Could someone please suggest a solution to bind keydown event on datatables? I want to capture ctrl+a key press, I have tried the following but none of them work.
$(tblNameId).on('keydown', function(event) {
		event.preventDefault();
		if (event.ctrlKey && event.which == 65) {			
			//Event captured
			}
		}
	});
	
	$(tblNameId).on('keypress', function(event) {
		event.preventDefault();
		if (event.ctrlKey && event.which == 65) {			
			//Event captured
			}
		}
	});
	
	$(tblNameId).on('keyup', function(event) {
		event.preventDefault();
		if (event.ctrlKey && event.which == 65) {			
	//Event captured
			}
		}
	});

Click event not responding

$
0
0
Hi, pretty new to this, but I'm trying to get a alert when a row in table is clicked. Can't get any response...
  <?php echo $this->Html->script('jquery-1.11.0.min'); ?>
  <?php echo $this->Html->script('jquery-ui-1.10.4.custom.min'); ?>
  <?php echo $this->Html->script('jquery.dataTables.min'); ?>
  
  <script type="text/javascript">
  $(function() {
  	$('#articles-table').dataTable({
  		"bProcessing": true,
		"bServerSide": true,
		"sAjaxSource": "<?php echo $this->Html->Url(array('controller' => 'Articles', 'action' => 'ajaxData')); ?>"
    });
    
	$('#articles-table tbody tr').live('click', function () {
    	alert('hej');
    });
});
</script>
<table id="articles-table">
	<thead>
		<th>Artikelnummer</th>
		<th>Benämning</th>
		<th>Typ</th>
		<th>Benämning 1</th>
	</thead>
	<tbody>
		<tr>
			<td colspan="4" class="dataTables_empty">Loading data from server...</td>
		</tr>
	</tbody>
  </table>

http://debug.datatables.net/oritem

Please advice me! Thanks in advance!

Emil Abrahamsson

SDom custom toolbar, buttons not toggling

$
0
0
I have a custom toolbar showing in my dataTable that has a few bootstrap buttons. The buttons show and do what I want them to but they should toggle (so if one is clicked, the others are not) but for some reason mine all stayed showing as clicked. I'm not sure if I have to do something so they don't show as clicked if I click a different one or not. Here is some of my code:

build the toolbar....
tb = "";
tb += "<div class='btn-group btn-group-sm' style='margin-top:10px;' data-toggle='buttons-radio'>";
tb += "<button type='button' data-filter-value='' class='btn btn-primary filter-btn'>Show All</a>";
tb += "<button type='button' data-filter-value='On Track' class='btn btn-primary filter-btn'>On Track</a>";
tb += "<button type='button' data-filter-value='With Issues' class='btn btn-primary filter-btn'>With Issues</a>";
tb += "<button type='button' data-filter-value='Critical' class='btn btn-primary filter-btn'>Critical</a>";
tb += "<button type='button' data-filter-value='No Status' class='btn btn-primary filter-btn'>No Status</a>";
tb += "</div>";

part of the DataTable - most I didn't think was relevant
oTable = $('#example').dataTable( {
"bAutoWidth":false,
"bProcessing": false,
"bDestroy": true,
"aaData": data,
"sDom": '<"toolbar">frtip',
"aoColumns": [

makes the toolbar show using the above built html.....
$("div.toolbar").html(tb);
$(".filter-btn").click(function(){
$("#example").dataTable().fnFilter($(this).data("filterValue"),5);
});

I used what I could find in your documentation to form this. Like I said, it does function but the buttons don't toggle. Any ideas?

Sort descending on first click

Datatables server side processing Urgent !

$
0
0
Hi All,
I am struggling to understand the datatable implementation of the server processing. My usecase is I want to use datatable with server side processing since I will be dealing with large set of data.

We use JSF for web application.I am just wodering if anybody has an example of JSF with datatable.Also the documentation says that we
need some kind of server side script to get the data from the database. WHat we would liek to do is call a java function on the server side which will eventually connect to the database.

Does anybody have a insight into this ?

Thanks,'VJ

datatable with selectbox which is having the column names

$
0
0
hi ,

i need some suggestions from u, in data table header i have a select box which is having the column names(its I18N application) and on text box. when i select the column name from the select box and i am typing the some words into the text box, search need to happens in the particular column.
ex: table having the sno, name and first name
and select box having the total 4 values.
one is "select any one" and 3 column names. if the person select any table column names.that search should be happens in that particular column.by default -"table search" will be there, if the person didn't select any thing from the select box

thanks in advance

How can we enable locking on the editable fields in Data Tables?

$
0
0
I'm currently using jEditable plugin to make some columns in the table editable. However, since the page can be accessed by multiple people at the same time I'm concerned about the consistency issues. Is there a way that you can use the concept of locks for adding data synchronization to the table? Any ideas would be greatly appreciated.

Show 10, 25 entries not working in IE 8.

$
0
0
Hi,

Following is the code to create my table. I have initialized iDisplayLength to 200. When I click on Show 10, it does nothing, still displays the 200 records. This is happening in IE8, but it works in Chrome. Please advise on how to get this to work on IE8.

(function($) {

var myDataTableDefaults = {
"sPaginationType": "full_numbers",
"iDisplayLength": 200,
"aLengthMenu": [[10, 25, 50, 100, 200, -1], [10, 25, 50, 100, 200, "All"]],
"oLanguage": {
"sSearch": "Filter:"
},
"fnInitComplete": function(oSettings, json) {
$(".loadingPageDomAnimation").hide();
$('.dataTable').fadeIn('slow');
},
"sEmptyTable": "No record found"
};

$.fn.myDataTable = function (options) {
options = $.extendmyDataTableDefaults, options);
return this.dataTable(options);
};
})(jQuery);

Thank you.

Need to access accordion hidden rows

$
0
0
I currently have a table that uses the accordion feature. If 200 rows load only 10 are shown at a time. Each row has a checkbox so a user can select the row. Works great except when a user selects some rows, paginates to a new page and then selects some more rows. If I paginate back and forth I see all the row are still selected. When I go to find out how many rows have been selected by code only returns the ones that are visible.

This is the line of code I currently use to get me a list of selected rows:
var selectedLogIds = $('#wellList .pdsSubTable').find('input:checked').map(function(i, item) { return item.value; }).get();

Is there a setting somewhere to allow this to return even the selected rows that are not actively being displayed?

Pagination / Four-button / Option / Conditionally Display/Suppress text labels

$
0
0
Hi Allan,

I was wondering if you have ever fielded this request:
When using 4-button pagination, I'd like to communicate FIRST, LAST, NEXT and PREV with icons.
Is there a way to tell the plugin to refrain from injecting the equivalent text strings?

(Yeah, I know I can target the anchor tags with Jquery and omit the text - shown below - but that feels like a bad surgeon wielding an axe.)
// See if full number pagination has been elected
       var _p = $('.dataTables_paginate.paging_full_numbers');

// Remove Next/Previous text
        if ( _p.length ) {
            // Reselect to get only anchors without spans which hold page numbers
            // That is, we want only First, Previous, Next and Last. 
            $('.dataTables_paginate.paging_full_numbers > a').text("");
        };

[SOLVED] Getting data for the datatables using WHERE statement then still allow filtering

$
0
0
Hi all,

I am new to DataTables and I am trying to get some data to display. I want to only select data from the db WHERE field_name IS NOT NULL then be able to filter the results. How do I go about doing this. I have searched and searched but not found anything too helpful. By the way I am a noob so expect stupid questions! haha!

I have added the code below to the processing file:

$sWhereNew = "field_name IS NOT NULL ";

/*
* SQL queries
* Get data to display
*/
$sQuery = "
SELECT SQL_CALC_FOUND_ROWS `".str_replace(" , ", " ", implode("`, `", $aColumns))."`
FROM $sTable
WHERE $sWhereNew
$sWhere
$sOrder
$sLimit

This filters the results and shows at the bottom xxxx results filtered from xxxx but then I cannot use the search bar to filter further. What am I doing wrong?!

Thanks for any help!!

Performance with 267 columns 117 rows

$
0
0
I'm currently investigating a browser-freezing problem when using a large number of columns. I'm having a bit of trouble where to look because I'm rather new to browser/JS profiling.

However, I *think* what's happening is that the browser chokes on reflow. Because many of the bottlenecks are single statements - they are getting or setting sizes. Which I presume cause a storm of recomputations for something as complex as a table with so much columns. Maybe there's also a possible influence from the Scroller add-on (release 1.2.0) ?

For a smaller number of columns there seems to be no problem.

Is this a problem already familiar to somebody in here ?

Or any hint what alternatives I can try ? Preferably by maintaining that many columns. :-)

Thanks !

Jan

Performance issue HTML/sScrollY

$
0
0
Hey,

i've a performance issue with a DataTable that does not exceed the recommendations of 5000 records. It is a simple table width a dom-table as datasource. The zero-configuration with 2000 items is very fast (under my hardware-configuration: 800ms), also with bPaginate=false. But if i use html (span, a, etc.) in a td, the datatable slow down (1600ms). Not very fast, but ok. But if i enabe sScrollY and bScrollCollapse, the table needs more than 4000ms to render.

My questions:
1. Why html in a td slow down the datatable? Maybe internal type detection or text extraction?
2. Why is sScrollY so slow and how can i make it faster? Scroller or bPaginate=true are no options.

JSFiddle: http://jsfiddle.net/6HXX9/10/

Thanks for your help!

Looping through an array of json objects

$
0
0
I have JSON object returned by AJAX call like below

{
"aaData":[
{"type":"type1","ratings":[
{"date":"01-Jul-2013","rating":"A","ratingType":"FLT"},
{"date":"02-Jul-2013","rating":"B","ratingType":"LLT"},
{"date":"03-Jul-2013","rating":"C","ratingType":"MLT"},
{"date":"04-Jul-2013","rating":"D","ratingType":"NLT"}]},

{"type":"type2","ratings": [

{"date":"05-Jul-2013","rating":"AA","ratingType":"RT1"},
{"date":"06-Jul-2013","rating":"BB","ratingType":"RT2"},
{"date":"07-Jul-2013","rating":"CC","ratingType":"RT3"},
{"date":"08-Jul-2013","rating":"DD","ratingType":"RT4"}]}
]
}

I need to draw the data table like below using the above JSON object. JSON object may have n number of types.

type1
Date Rating Rating Type
1-Jul-13 A FLT
2-Jul-13 B LLT
3-Jul-13 C MLT
4-Jul-13 D NLT
type2
Date Rating Rating Type
5-Jul-13 AA RT1
6-Jul-13 BB RT2
7-Jul-13 CC RT3
8-Jul-13 DD RT4

Please let me know how to loop the above JSON object and display the columns.

Clustered Table / subtotal sorting help

$
0
0
http://live.datatables.net/bomogov/1/edit?html,js,output

What I'm trying to do is create a table with subtotal rows contained internally, and have each section sort independently. For example, lets say I want to look at my inventory, and have shortages separated from surpluses. I want the shortages in one section, with a subtotal, and the surpluses the same way. Each of those sections should sort independent of the other, with the subtotals remaining at the bottom of the respective sections.

I've come up with some expanded sort methods to handle this, but I'm finding that they function inconsistently. The first time you perform a sort on the page, it will sort correctly, but any subsequent sorts will not sort properly (although the items stay in their proper sections, and the subtotals do not move). This is the case even if the sort is a repeat of the original sort.

$.fn.dataTableExt.afnSortData['clustered'] = function(oSettings, iColumn)
{
	//iColumn = item_table.fnColumnIndexToVisible(iColumn);
	var aData = [];
	$('td:eq(' + iColumn + ')', oSettings.oApi._fnGetTrNodes(oSettings) ).each( function () {
		aData.push(this.parentNode.getAttribute('grouping') + ' ' + this.parentNode.getAttribute('rowtype') + ' ' + this.innerHTML);
		
	} );
	return aData;
}

jQuery.extend( jQuery.fn.dataTableExt.oSort, {
    "clustered-numeric-pre": function ( a ) {
	var a_fields = a.split(' ');
	var a0 = parseInt(a_fields.shift());
	var a1 = a_fields.shift();
	var a2 = a_fields.join(' ');

	switch(a1) {
		case "head": a1 = 1; break;
		case "body": a1 = 2; break;
		case "foot": a1 = 3; break;
		default: a1 = 4;
	}

	a2 = (a2=="-" || a2==="") ? 0 : a2*1;
        a2 = parseFloat(a2);
        return [a0, a1, a2];
    },
 
    "clustered-numeric-asc": function ( a, b ) {
	if (a[0] != b[0]) {return a[0] - b[0];}
	if (a[1] != b[1]) {return a[1] - b[1];}
	return a[2] - b[2];	
    },
 
    "clustered-numeric-desc": function ( a, b ) {
	if (a[0] != b[0]) {return a[0] - b[0];}
	if (a[1] != b[1]) {return a[1] - b[1];}
	return b[2] - a[2];	
    },
  
    "clustered-string-pre": function ( a )
    {
    var a_fields = a.split(' ');
	var a0 = parseInt(a_fields.shift());
	var a1 = a_fields.shift();
	var a2 = a_fields.join(' ');

	switch(a1) {
		case "head": a1 = 1; break;
		case "body": a1 = 2; break;
		case "foot": a1 = 3; break;
		default: a1 = 4;
	}
                  
    if ( typeof a2 != 'string' ) {
           a2 = (a2 !== null && a2.toString) ? a2.toString() : '';
        }
        return [a0, a1, a2.toLowerCase()];
    },

    "clustered-string-asc": function ( x, y )
    {
    if (x[0] != y[0]) {return x[0] - y[0];}
	if (x[1] != y[1]) {return x[1] - y[1];}
    return ((x[2] < y[2]) ? -1 : ((x[2] > y[2]) ? 1 : 0));
    },

    "clustered-string-desc": function ( x, y )
    {
      if (x[0] != y[0]) {return x[0] - y[0];}
	  if (x[1] != y[1]) {return x[1] - y[1];}
      return ((x[2] < y[2]) ? 1 : ((x[2] > y[2]) ? -1 : 0));
    }


} );

Any ideas on what isn't working right with this?

checkbox in datatables grid

$
0
0
Hello i want add first column as check box and also select/deselect all rows using header checked box, and also i want checked rows value..
how to possible this using this datatables grid.

Disable/enable Scroller for individual tables ?

$
0
0
I have a large data use case where Scroller *seems* to be a performance bottleneck. Especially those with +30 columns. Scrolling down the rows is just a frustrating experience. BUT it gets less so when showing the classic pagination buttons. At least, at what I hope. :-)

However, Scroller remains the preferred way of handling large data sets. My intention is to keep Scroller working by default. But disable it for tables with more than 30 columns.

The problem is that I need to keep both the .js files into the same page. Doing so Scroller will automatically register with DT. But in some cases it shouldn't.

Is there a way to disable selectively Scroller for specific tables ?

PHP jquery datatables with CRUD just can edit pages 1

$
0
0
Hello everyone,

I'm using jquery datatables but there's something problem.

I have total 11 records. Data tables show me 10 entries of record from database and I add column for edit and delete

when I click pagination button (next) , data tables show me record from pages 2 (record number 11 etc), but the button of edit and delete is not work

Can you help me ?

this is my link to the application

http://49.128.179.27/kbk_si/pages/ketua/data_dosen

Hope can help me :) because i'm newbie for datatables

Secho Error

$
0
0
http://debug.datatables.net/ehopuw

Hi I have been trying to integrate datables into my intranet site and i am having trouble with sEcho returning as 0, I am a complete novice with Jscript all my experience is with PHP any help would be greatly appreciated.

Thanks

Wayne
Viewing all 1816 articles
Browse latest View live