What's the best data source for me to use?
What's the best data source for me to use?
Hello!
I just staring using the datatable and love it. The default sorting, paging and filtering has saved me countless hours. Currently I get my data on the page and dynamic build the HTML table and that works perfect. My test table has Project Name, Date, Contact Person and Status. Although the users could use the default filter box for these fields, there are a bunch of Status options which they would not know all the values to type into the default filter box. So I prefer to create a dropdown box with the status options in it from which they can pick. Once they select a status in this dropdown I want to reload the data so that I can continue to use the default paging, filtering and sorting. This will not be a large list of projects (< 200) so was not thinking I need server side processing. Is there a way to just rebuild the table in the DOM and have the table regenerate?
Thanks!
I just staring using the datatable and love it. The default sorting, paging and filtering has saved me countless hours. Currently I get my data on the page and dynamic build the HTML table and that works perfect. My test table has Project Name, Date, Contact Person and Status. Although the users could use the default filter box for these fields, there are a bunch of Status options which they would not know all the values to type into the default filter box. So I prefer to create a dropdown box with the status options in it from which they can pick. Once they select a status in this dropdown I want to reload the data so that I can continue to use the default paging, filtering and sorting. This will not be a large list of projects (< 200) so was not thinking I need server side processing. Is there a way to just rebuild the table in the DOM and have the table regenerate?
Thanks!
This discussion has been closed.
Replies
http://datatables.net/api#fnFilter
// Status dropdown change.
$("#status-select").change(function () {
// We have a new filter so get the new data.
alert('In the status-select change event');
// Get the current status.
var currentStatus = $('#status-select').val();
// Get the table.
$('.sortable').each(function (i) {
// DataTable config
var table = $(this),
oTable = table.dataTable({
oTable.fnFilter('Lead');
});
};
});
// Customized fnReloadAJAX to allow for new source.
$.fn.dataTableExt.oApi.fnReloadAjax = function (oSettings, sNewSource) {
if (typeof sNewSource != 'undefined') {
oSettings.sAjaxSource = sNewSource;
}
this.fnClearTable(this);
this.oApi._fnProcessingDisplay(oSettings, true);
$.getJSON(oSettings.sAjaxSource, null, $.proxy(function (json) {
for (var i = 0; i < json.aaData.length; i++) {
this.oApi._fnAddData(oSettings, json.aaData[i]);
}
oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
this.fnDraw(this);
this.oApi._fnProcessingDisplay(oSettings, false);
}, this));
}
I then defined my table as:
// Setup grid and use AJAX as the source.
$('#OppTable').dataTable({
"bProcessing": false,
"sAjaxSource": '/home/ReloadGrid',
"sDom": '<"block-controls"<"controls-buttons"p>>rti<"block-footer clearfix"lf>'
});
Then in my dropdown event handler I call the fnReloadAjax function with my URL and parameter of the selected status:
$("#status-select").change(function () {
// We have a new filter so get the new data.
// Get the current status.
var currentStatus = $('#status-select').val();
$('#OppTable').dataTable().fnReloadAjax('/home/ReloadGrid/?FilterValue=' + currentStatus);
});
With this I can use the paging, filtering and sorting all on the client side.
Thanks!