jqgrid自定义数字分页 [英] jqgrid Custom Numeric Pagination

查看:122
本文介绍了jqgrid自定义数字分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何更改jqgrid分页 例如: 第15页,共1页(150个项目)<< < 1 2 3 4 5 .. 12 13 15> >>

How to change jqgrid pagination like: Pages 1 of 15 (150 Items) << < 1 2 3 4 5.. 12 13 15 > >>

两个显示都在中心td中.

Both display in center td.

推荐答案

查看答案,其中提供了相应的演示.通常,您可以通过任何其他自定义方式创建寻呼机.你出租车.仅使用1 2 3 4 5 ... 12 13 15放置链接并为链接绑定click事件处理程序,这一点很重要.在事件处理程序内部,您只需要使用相应的page参数:$("#gridid").trigger("reloadGrid", [{page: newPage}]);在网格上触发reloadGrid事件.另请参见答案.

Look at the answer which provides the corresponding demos. In general you can create the pager in any other custom way. You cab . It's important just to place links with 1 2 3 4 5 ... 12 13 15 and bind click event handler for the links. Inside of the event handler you need just trigger reloadGrid event on the grid with the corresponding page parameter: $("#gridid").trigger("reloadGrid", [{page: newPage}]);. See the answer additionally.

更新:答案是3.5岁.该演示使用jqGrid 3.8.2版本.从版本4.3.2(当前为4.6)开始,jqGrid支持jQuery事件.它使您可以轻松地将其注册为一个事件处理程序.像loadCompleteonSelectRow这样的经典回调的缺点:只能有一个".例如,您不能使用寻呼机的初始化来定义一个 common 回调loadComplete,而要使用另外一个 specific 附加的 additional 回调loadComplete动作.您可以通过定义常见的loadComplete

UPDATED: The answer is 3.5 years old. The demos use jqGrid 3.8.2 version. Starting with version 4.3.2 (the current is 4.6) jqGrid supports jQuery events. It allows easy to register more as one event handler. Disadvantage of classical callbacks like loadComplete or onSelectRow: "there can be only one". You can't define one common callback loadComplete with initialization of pager for example and to use another additional callback loadComplete with specific additional actions. You can define common loadComplete by

$.extend(true, $.jgrid.defaults, {
    loadComplete: function (data) {
        ...
    }
});

,但如果在网格中定义loadComplete,它将被覆盖.另一方面,可以注册多个 jqGridLoadComplete或jqGridAfterLoadComplete事件处理程序,然后从那里调用所有事件处理程序. jQuery 追加事件处理程序列表,而不是覆盖它.

but it will be overwritten if one define loadComplete in the grid. On the other side one can register multiple jqGridLoadComplete or jqGridAfterLoadComplete event handlers and all from there will be called. jQuery appends the list of event handlers instead of overwriting it.

因此,要在一个包含许多网格的复杂项目中实现新功能,例如新的寻呼机,我可以建议您使用两个摘要.

So to implement new feature, like new pager, in a complex project which contains many many grids I can suggest you two snippets.

第一个需要对代码进行小的修改.查看该演示.网格选项不包含任何loadComplete回调,但包含以下行

The first one required small modification of the code. Look at the demo. Grid options don't contains any loadComplete callback, but includes the line

$grid.on("jqGridAfterLoadComplete", refreshPager);

之前创建网格$grid. refreshPager的代码是旧演示中loadComplete回调的修改后的副本.通过 multiple "jqGridAfterLoadComplete"事件处理程序可以注册.

before creating the grid $grid. The code of refreshPager is the modified copy of loadComplete callback from the old demo. In the way multiple "jqGridAfterLoadComplete" event handler can be registered.

您可以通过添加以下行来修改代码

You can modify the code by including the line

myjqGridInit($grid);

在每个网格之前,创建

并将myjqGridInit函数的代码放置在单独的.js文件中,该文件应包含在jquery.jqGrid.min.js之后.这样,您可以将jqGrid的所有常见项目初始化(例如$grid.on("jqGridAfterLoadComplete", refreshPager);的注册)放置在项目的一个位置.这样的项目维护起来会很容易.

before every grid creating and place the code of myjqGridInit function in separate .js file which you includes after jquery.jqGrid.min.js. In the way you can place all common project initialization of jqGrid (like registering of $grid.on("jqGridAfterLoadComplete", refreshPager);) in one place of your project. It will be easy to maintain such project.

如果到目前为止您不使用onInitGrid回调,我可以建议您使用第二种方法,该方法允许您使用jqGrid最小化现有页面的更改.如果在项目中使用母版页,则可能只需要在之后 jquery.jqGrid.min.js之后以及创建任何网格之前添加以下代码:

If you don't use onInitGrid callback till now I can suggest you the second alternative which allows you minimal changes of the existing pages with jqGrid. If you use master pages in your project you could need just include the following code after jquery.jqGrid.min.js and before any grid is created:

$.extend(true, $.jgrid.defaults, {
    onInitGrid: function () {
        refreshPager.call(this);
    }
});

上面的代码定义了默认的onInitGrid回调,该回调使所有项目初始化.您还可以将refreshPager的代码放在单独的.js文件中,并将其包括在母版页中.

The above code defines default onInitGrid callback which makes all project initialization. The code of refreshPager you can of case place in separate .js file too and just include it on the master page.

该演示演示了该代码段.通过这种方式,您可以在现有项目的 all jqGrids中实现新功能,而对代码的修改最少.唯一的限制:您不应在网格中使用onInitGrid回调,因为它会覆盖常见的初始化.

The demo demonstrates the snippet. In the way you could implement new feature in all jqGrids of your existing projects with minimal modification of the code. The only restriction: you should don't use onInitGrid callback in your grids, because it will overwrite the common initialization.

这篇关于jqgrid自定义数字分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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