Struts2 + Bootstrap datatable:如何分页,无需加载所有数据 [英] Struts2 + Bootstrap datatable: how to paginate without load all data

查看:940
本文介绍了Struts2 + Bootstrap datatable:如何分页,无需加载所有数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一些使用Struts2框架的应用程序中工作,在该操作中,我加载了一些 List< Object> 中所需的所有数据,然后在JSP中文件这个列表被迭代并使用引导框架显示在datatable中。



这个工作正常,但是我会知道如何在没有加载生成的HTML中的完整数据的情况下就像我有一个1000万的记录一样。



我不希望所有的记录都在JSP的结果HTML输出中,只有第10个,并且分页加载(使用jQuery?)

解决方案

嗯,这是一个很好的aproach,但是我必须转换request.getParameter struts变量(声明为privated,然后生成getter y setter):



FROM: https://datatables.net/development/server-side/jsp



编辑:此链接有一些请求.gP与数据表中的旧值相反,我们必须使用以下参数:



https://datatables.net/manual/server-side#Sent-parameters



喜欢在一个动作:

  private String draw; 

private String length;

私人字符串顺序;

私人字符串搜索;

private String start;

getters& setters {} //或使其公开

然后在由ajax调用的actionMethod使得查询到db并返回数据集。



当我有完整的分页处理struts2 +数据表时,我将编辑此答案,



在数据表中有一些必需的配置(请参阅datatables.net中的文档):

 < script> 
$(document).ready(function(){
$('#datatable')。dataTable({
iDisplayLength:5,
processing
serverSide:true,
ajax:paginateTableAction
});
});
< / script>


I'm working in some app that uses Struts2 framework and in the action i load all the data that we need in some List<Object> and then in the JSP file this list is iterated and displayed in a datatable using bootstrap framework.

This works fine, but i would know how to do this without load the full data in the resulting HTML, like if i have 1.000.000 (one million) of records.

I don't want that all the records are in the resulting HTML output from the JSP, only the 10 first, and with the pagination load (with jQuery?) the rest of the dataset if is needed.

解决方案

Well, this is some good aproach, but i have to convert the request.getParameter to struts variable (declared as privated and then generate getters y setters):

FROM: https://datatables.net/development/server-side/jsp

edit: This link have some request.gP with old values from the datatables, instead we have to use the params from:

https://datatables.net/manual/server-side#Sent-parameters

Like in an action:

private String draw;

private String length;

private String order;

private String search;

private String start;

getters&setters{} //or make it public

Then in the actionMethod that is called by the ajax make the query to the db and return the dataset.

I will edit this answer when i have the full pagination working with struts2+datatables,

In the datatable there is some configurations that are necesary (see the docs from datatables.net):

<script>
$(document).ready( function() {
    $('#datatable').dataTable( {
      "iDisplayLength": 5,
      "processing": true,
      "serverSide": true,
      "ajax": "paginateTableAction"
    } );
  } );
</script>

这篇关于Struts2 + Bootstrap datatable:如何分页,无需加载所有数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆