如何在服务器端处理C#和WebMethod中使用jQuery DataTables?

时间:2015-11-24 11:50:45

标签: c# jquery json ajax datatables

是否有使用 DataTables jquery和C#服务器端处理示例进行分页,排序,搜索和不使用LINQ?

1 个答案:

答案 0 :(得分:0)

我找到了这个解决方案,它对我有用:

$('#usersList').dataTable({
                        "sPaginationType": "full_numbers",
                        "bDestroy": true,
                        "bProcessing": true,
                        "bServerSide": true,
                        "bDeferRender": true,
                        "aaSorting": [[2, 'asc']],
                        "oLanguage": {
                            "sProcessing": '<div class="splash-title"><img src="images/loading-bars.svg" width="64" height="64" /></div'
                        },
                        "sAjaxSource": "AJUserManagement.aspx/GetAJUsers",
                        "fnServerData": function (sSource, aoData, fnCallback) {
                            $.ajax({
                                "dataType": 'json',
                                "contentType": "application/json; charset=utf-8",
                                "type": "GET",
                                "url": sSource,
                                "data": aoData,
                                "success": function (msg) {
                                    var json = msg.d;
                                    fnCallback(json);
                                }
                            });
                        }});
json应该是一个json对象包含一个对象列表, recordsTotal =总记录,应该来自数据源和 recordsFiltered =过滤记录,应该来自数据源