使用DataTables插件的服务器端分页

编程入门 行业动态 更新时间:2024-10-28 18:34:01
本文介绍了使用DataTables插件的服务器端分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

服务器每页返回15条记录,总记录超过2000条.我想显示前15条记录,然后单击下一步"按钮时,显示剩余的所有记录,(每页15条) ). 为此,我们要做服务器端分页还是客户端??

The server is returning 15 records per page and the total records are over 2000. I'd like to display first 15 records and then on every click of the 'Next' button , display the remaining all records, (15 per page). For this do we do a server side pagination or client side???

这是我的表和 DataTables 中用于分页的属性:

Here is my table and the attributes I'm using for pagination in DataTables:

var tableData = self.accountCollection.getData(); var tableColumns = this.accountCollection.getColumns(); var totalRecs = this.accountCollection.length; //create the UI grid containing the list of items this.resultsTable = tableEl.dataTable( { "bServerSide": true, "sEcho": 3, "iTotalRecords": totalRecs, "iTotalDisplayRecords": 15, "aaData": tableData, "aoColumns": tableColumns, "aaSorting": [[1,'asc']], }); getData: function () { var returnData = []; $.each(this.models, function (idx, accountModel) { returnData.push(accountModel.attributes); }); return returnData; },

returnData将为我返回一个对象,该对象具有要在表中填充的字段.

The returnData will return me an Object that has fields I will be populating I a table.

大致返回对象:

Object accountName: "No Company" address1: "1234 asdf" address2: "" billingAcctId: null billingSystem: null city: "mountain view" comments: null country: "USA"

然后将使用以下方法调用getData()函数以从数据库返回数据:

The getData() function will be then called to return the data from the database using:

var tableData = this.accountCollection.getData()

因此,基本上tableData将具有必要的字段和值以显示在表中.现在,我可能已经从服务器返回了1000多个记录.因此,我需要分页.

So basically tableData will have the necessary fields and values to display in table. Now I may have more than 1000 records returned from the server. Hence I needed pagination.

小提琴手是我尝试过的方法,对paginatin没有任何影响.

The one in fiddle is what I tried and does not have any impact on the paginatin.

我认为我具有DataTables随附的基本分页功能,但是现在我需要有一个服务器端,一次只能显示15条记录,然后单击下一步"和上一步"按钮,应该能够进行ajax调用,以获取每页剩余的记录15.

I think I have the basic pagination that comes with the DataTables, but now I need to have a server side, to get only 15 records to display at a time, and on click of 'next' and 'prev' button i should be able to make ajax calls to get the remaining records 15 per page.

我希望这可以帮助您更好地理解.如果您需要更多详细信息,请告诉我.

I hope this helps you understand better. Please let me know if you need more details.

如何使用DataTables实现分页?

How can I achieve pagination using DataTables?

谢谢

推荐答案

分页会显示您需要执行的以下最小更改的总记录记录.

Pagination works total displayed record you need to perform following minimum changes.

"iTotalDisplayRecord"将是已过滤的记录总数

"iTotalDisplayRecord" will be total filtered records

更多推荐

使用DataTables插件的服务器端分页

本文发布于:2023-11-22 23:52:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1619385.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:分页   服务器端   插件   DataTables

发布评论

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

>www.elefans.com

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