首页 新闻 会员 周边

Jquey easyUI 分页查询

0
悬赏园豆:10 [已解决问题] 解决于 2017-04-10 09:29

目前直接在 HTML 声明datagrid组件,但是需要写查询参数都不方便,后来编写 JavaScript 代码来创建datagrid组件,但是发现分页时直接查询出后台数据库所有数据后再分页,这样效果不好,影响效率。
请问有没有办法实现点击分页按钮后根据页码和记录数实现分页查询?请问如何修改下面的代码,谢谢!

附上 HTML 声明datagrid组件

<table id="dg" title="My Users" class="easyui-datagrid" style="width:700px;height:250px"
            url="get_users.php"
            toolbar="#toolbar" pagination="true"
            rownumbers="true" fitColumns="true" singleSelect="true">
        <thead>
            <tr>
                <th field="firstname" width="50">First Name</th>
                <th field="lastname" width="50">Last Name</th>
                <th field="phone" width="50">Phone</th>
                <th field="email" width="50">Email</th>
            </tr>
        </thead>
    </table>

lwr的主页 lwr | 初学一级 | 园豆:48
提问于:2017-03-27 13:55
< >
分享
最佳答案
0

传过去了页数和每页显示数据条数,分页查询放在数据库语句中,用LIMIT

收获园豆:10
软件杨威 | 初学一级 |园豆:26 | 2017-03-27 14:37

我想问下,如果有查询参数的条件应该怎么写呢?是用JavaScript 代码来创建,还是继续在 HTML 声明中写查询条件呢?

lwr | 园豆:48 (初学一级) | 2017-03-28 08:09

你可以用js动态创建datagrid

$(function() { $("#table").datagrid({ url : 'queryroles.do', columns : [ [ { field : 'id', width : 100, title : '编号' }, { field : 'name', width : 150, title : '职位名称' }, { field : 'desc', width : 200, title : '简介' }, { field : '_op', title : '操作', width : 100, formatter : function(v, r, i) { var s = "删除"; return s; } } ] ], singleSelect : true, pagination : true }); });

然后直接传参数进去

//根据条件查询角色 $('input[type=button]').click(function(){ var v = $('#roleName').val(); $('#table').datagrid('load',{ roleName:v }); });

软件杨威 | 园豆:26 (初学一级) | 2017-03-28 09:15

@lwr: 其实你仔细阅读一下easyui的API文档就知道怎么写了,里面都有,http://pan.baidu.com/s/1dFACpzz

这里面有文档

软件杨威 | 园豆:26 (初学一级) | 2017-03-28 09:17
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册