jQuery Datatable:分页和过滤器不正确显示

编程入门 行业动态 更新时间:2024-10-12 05:44:51
本文介绍了jQuery Datatable:分页和过滤器不正确显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我不知道如何解决这个问题,尝试一整天,但没有成功修复分页。我正在使用jQuery datatable,并显示我的巨大数据,我正在使用服务器端。

作为测试,只能将10行数据调用到表中。然后在传递给表之前,我使用这个

数据过滤器和分页不正确,应该只有1页的分页。

解决方案

我有一个解决方案。您应该直接修改您的回复对象。

dataSrc:function(data){ var json = $ .parseJSON(data.d); data.draw = parseInt(json.otherData [0] .draw); data.recordsTotal = parseInt(json.otherData [0] .recordsTotal); data.recordsFiltered = parseInt(json.otherData [0] .recordsFiltered); data.data = json.searchData; return data.data; }

希望它适用于您的情况。

I dont know how to solve this, try a whole day but didn't success to fix the pagination. I'm using jQuery datatable, and to display my huge data, I'm using server side.

As a testing, only call 10 row of data to the table. Then before pass to table, I restructured the data inside dataSrc, using this solution . The table display successfully but the pagination and filter not display correctly.

Can anyone help this.

Below is my code.

AJAX

$('#example').DataTable({ "processing": true, "serverSide": true, "ajax": { type: "POST", contentType: "application/json; charset=utf-8", url: "datatables.aspx/GetData", 'data': function (data) { return JSON.stringify(data); }, "dataSrc": function (data) { var json = $.parseJSON(data.d); var myData = {}; myData.draw = parseInt(json.otherData[0].draw); myData.recordsTotal = parseInt(json.otherData[0].recordsTotal); myData.recordsFiltered = parseInt(json.otherData[0].recordsFiltered); myData.data = json.searchData; return myData.data; } }, "columns": [ { "data": "Username" } ] } });

C#

[WebMethod] [ScriptMethod(UseHttpGet = false)] public static string GetData(int draw, object columns, object order, int start, int length, object search) { string constr = ConfigurationManager.ConnectionStrings["DBConnection"].ConnectionString; using (SqlConnection con = new SqlConnection(constr)) { string mySql = "SELECT TOP 10 username AS Username FROM user_lookup"; using (SqlCommand cmd = new SqlCommand(mySql, con)) { using (SqlDataAdapter sda = new SqlDataAdapter(cmd)) { con.Open(); DataSet ds = new DataSet(); sda.Fill(ds, "searchData"); DataTable newDT = new DataTable("otherData"); //Add columns to DataTable. newDT.Columns.AddRange(new DataColumn[4] { new DataColumn("draw"), new DataColumn("recordsTotal"), new DataColumn("recordsFiltered"), new DataColumn("userRole") }); //Add rows to DataTable. newDT.Rows.Add(draw, length, start, "myrole"); ds.Tables.Add(newDT); string JSONString = string.Empty; JSONString = JsonConvert.SerializeObject(ds); return JSONString; } } } }

This is the data I return back to datatable to structured the table.

Data filter and pagination not correct, should be only 1 page of pagination.

解决方案

I have a solution for our case. You should modify the object of your response directly.

"dataSrc": function (data) { var json = $.parseJSON(data.d); data.draw = parseInt(json.otherData[0].draw); data.recordsTotal = parseInt(json.otherData[0].recordsTotal); data.recordsFiltered = parseInt(json.otherData[0].recordsFiltered); data.data = json.searchData; return data.data; }

Hopefully, it works in your case.

更多推荐

jQuery Datatable:分页和过滤器不正确显示

本文发布于:2023-11-09 21:15:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1573457.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:分页   过滤器   不正确   jQuery   Datatable

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!