c# - How to use JQuery "datatable" plugin server side processing with large data in .NET MVC3 razor views -
i have datatable displays list of employees. works fine when number of employees in 0-2000 range after there serious lag time when loading page. not surprizing since loading massive amount of data on page load. looked everywhere , couldnt find example shows how server side processing. projects found on git hub not working in computer(i got lot of "missing references" errors). code have working right now
the employees.cshtml
@model employeelist @{ layout = null; viewbag.title = "employees"; } <html> <head> <head/> <body> <table id="employees_gridview"> <thead> <tr> <th name </th> <th> username </th> <th> job category </th> <th> hire date </th> </tr> </thead> <tbody> @if (model.rowlist != null) { foreach (var item in model.rowlist) { <tr> <td > @html.displayfor(i => item.displayname) </td> <td > @html.displayfor(i => item.username) </td> <td> @html.displayfor(i => item.jobcategoryname) </td> <td> @html.displayfor(i => item.hiredate) </td> </tr> } } </tbody> <tfoot> </tfoot> </table> </div> </div>
the datatable jquery looks this
$(document).ready(function(){ $('#employees_gridview').datatable({ "bdestroy":true, "bsortclasses": false, "bdeferrender": true, // here default setting number of results show on page "idisplaylength": 10, "bjqueryui": true, "spaginationtype": "full_numbers", "aasorting" :[], // here column specific settings "aocolumns": [ {"atargets": [ 0,1 ]}, null, {"sclass": "datatablecentercolumn"}, {"stype":"date", "sclass": "datatablecentercolumn" }] }); });
and controller method processes page load request
public actionresult index() { employeelist employeelist = getemployeelist(); return view("index", employeelist ); }
can please show me how can change client side datatable server side processing datatable.
i've used jquery datatables plugin code before, , if data (i.e., localhost), still slow -- spending lots of time in javascript/dom manipulation. make fast must virtualize jquery datatable. so, have modify both client & server code.
step 1) need have repeatable sql proc returns appropriate subset of rows. have 2000 rows total, need stored proc like
getemployedatarows(@startingrow) -- or pagenumber, or whatever convenient you.
make sure have stable query can "subsetted" appropriately. key step 1 want fast. row# or page# may not choice. if returnng rows in primary key orded, example, may smarter pass subset parameter @empnum , include employeenumber > @empnum in getemployedatarows
step 2) expose webservice (json based best browser consumption) takes startingrow (etc.) parameter(s)
step 3) -- virtualize database based on json service.
so, not trivial task, right way solve this. there plenty of examples each of these steps.
-- followup should have been clearer, datatables slow if have lots of data, never recommend using without virtualization if have 1000 rows of 20 columns, sluggish me. if use support old ie of course slower normal.
Comments
Post a Comment