Jquery Datatable Server Side processing in ASP.NET MVC application
Jquery Datatable Server Side processing in ASP.NET MVC application
Hi,
I am using Jquery Datatable Server side processing in an ASP.NET MVC application. The table gets rendered properly but the controller method which is defined as server side processing method gets called repeatedly (4 to 5 times). Also, when I redirect to some other page, this method gets called.
Below are the properties set for server side processing
oTable = $('#activitiesTable').dataTable({
"bStateSave": true,
"sPaginationType": "full_numbers",
"aaSorting": [[5, "asc"]],
"bServerSide": true,
"sAjaxSource": "FilterActivitiesData",
"bProcessing": false,
"sServerMethod": "POST"
})
Please help me to understand what can be the reason behind multiple calls to server side method.
Thanks in advance.
Answers
Hi pras9224,
I am not sure why your behavior is happening, but maybe it can help if I show you how I create my DataTables using MVC:
Hope this helps,
I don't see anything wrong with your code. Could you link to the page so we can take a look and debug it please?
Allan
Hi allan, Ashbjorn
Thanks for the response.
Please see below link, my problem is due to same reason mentioned in it.
http://stackoverflow.com/questions/15478081/datatables-generating-multiple-server-side-requests
In my case, I am also using fnSetColumnVis() function to hide some columns based on User Role.
I am hiding 4 columns, so it is calling server method 4 times additionally.
Few more observations:
When I am not hiding any column, in that case server side method is getting called 2 times as I have one default sort column.
When I have some search string in search box, in that case server side method is getting called 3 times.
So when I hide 4 columns now, server side method was getting called 6 or 7 times.
What I think is, it is calling server side method first time for rendering datatable, 2nd time for sorting, 3rd time if search string is present and then for each column which is hidden using fnSetColumnVis().
Can you please suggest any better approach to avoid this? Or let me know if my above analysis is wrong somewhere.
If you use the
columns().visible()
method to hide columns it will not perform a redraw (i.e. an Ajax request).Allan
Thanks allan.
using columns().visible() has solved the issue.
But columns().visible() is an DataTable api and in order to use it I need to initialize datatable as $( '#activitiesTable').DataTable() this as it returns DataTables API.
and $( '#activitiesTable' ).dataTable() this returns jQuery object.
$( '#activitiesTable').DataTable() by using this I am not able to use Datatable functions like fnDisplayStart().
Can you please suggest an approach so that I can use both DataTable functions as well as DataTable API?
The best thing to do would be to upgrade to the new API fully. But if you want to access both the legacy and "new" API, then the API reference page shows how:
Allan
Thanks allan. Its working for me now.