ASP NET component which adds functionality for automatic server side processing for the famous table plugin for jQuery.
Supports:
- Paging;
- Searching;
- Sorting;
- Custom filters: Less Than, Less than or equal, Greater than, Greater than or equal and Equal;
- Nested objects;
Currently tested with Entity Framework versions 6.0.0 and 6.2.0 and Datatables version 1.10.16.
Install-Package jQDataTables.ServerSide.MVC5
For how to install the jQuery Datatables plugin refer to the official documentation here
Here you can find how to configure for server side processing.
In order to map the ajax response to the correct columns the columns property must be configure in the configuration object.
var table = $('table').DataTable({
"proccessing": true,
"serverSide": true,
"ajax": {
url: "path to the data source",
type: 'POST'
},
"language": {
"search": "",
"searchPlaceholder": "Search..."
},
"columns": [
{ "data": "CustomerID", "searchable": false },
{ "data": "Person.FirstName", "searchable": true },
{ "data": "Person.LastName", "searchable": true },
{ "data": "Store.Name", "searchable": true },
]
});
Read how to use on the client side from here
The searching is performed only on string columns. Therefore the searchable parameter inside the columns property must be set to false. Only the string columns with the searchable parameter set to true will be included in the search.
Read how to use on the client side from here.
For all string columns the individual column filter will work as case insensitive search. For other types it will match the exact value. For DateTime types it will match the value with precision to the seconds.
Read how to use on the client side from here.
To use the predefined custom filters the data property of the configuration object must be configured properly link.
The following custom filters are supported on the server side:
gt
: greater than;gte
: greater than or equal;lt
: less than;lte
: less than or equal;eq
: eqaul;
<div>
CreditRating: from <input type="number" id="minCreditRating" value="1" class="reload-table" />
to <input type="number" id="maxCreditRating" value="3" class="reload-table" />
</div>
<div>
Business Entity ID = <input type="number" id="businessEntityId" value="" class="reload-table" />
</div>
<div>
Modified Date = <input type="date" id="modifiedDate" value="" class="reload-table" />
</div>
<div>
Account Number = <input type="text" id="accountNumber" value="" class="reload-table" />
</div>
<table id="SearchResultTable" class="display" cellspacing="0" width="100">
<thead>
<tr>
<th>BusinessEntityID</th>
<th>CreditRating</th>
<th>ActiveFlag</th>
<th>AccountNumber</th>
<th>ModifiedDate</th>
</tr>
</thead>
<tfoot>
<tr>
<th>BusinessEntityID</th>
<th>CreditRating</th>
<th>ActiveFlag</th>
<th>AccountNumber</th>
<th>ModifiedDate</th>
</tr>
</tfoot>
</table>
@section Scripts {
<script>
var table = $('#SearchResultTable').DataTable({
"proccessing": true,
"serverSide": true,
"ajax": {
url: "@Url.Action("GetVendorsData", "Vendors")",
type: 'POST',
"data": function (d) {
d.custom = {
"filters": {
"CreditRating": { "gte": $('#minCreditRating').val(), "lte": $('#maxCreditRating').val() },
"BusinessEntityID": { "eq": $('#businessEntityId').val() },
"ModifiedDate": { "eq": $('#modifiedDate').val() },
"AccountNumber": { "eq": $('#accountNumber').val() },
}
}
}
},
"language": {
"search": "",
"searchPlaceholder": "Search..."
},
"columns": [
{ "data": "BusinessEntityID", searchable: false },
{ "data": "CreditRating", searchable: false },
{ "data": "ActiveFlag", "searchable": false },
{ "data": "AccountNumber", searchable: true },
{ "data": "ModifiedDate", "searchable": false},
],
"columnDefs": [
{
"render": function (data, type, row) {
date = new Date(parseInt(row.ModifiedDate.replace("/Date(", "").replace(")/", ""), 10));
return date.toLocaleDateString();
},
"targets": 4
}
]
});
$('.reload-table').on('change', function () {
table.ajax.reload();
});
</script>
}