如何在jqGrid中创建非数据库列? [英] How do I make a non database column in jqGrid?

查看:165
本文介绍了如何在jqGrid中创建非数据库列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想即时计算总计,而无需在calctotal.php中进行.本质上,这是一个计算列.我曾想过使用 afterInsertRow 之类的事件,但是即使没有事件,它也会将列数据移动一位,因为XML文件只有3列而不是4列.因此,我的 Total 列现在具有来自 Notes 的数据,我确实在php文件中添加了一个伪列,但是为什么我必须这样做?谢谢

I would like to calculate Total on the fly without havng to do it in calctotal.php. In essense this is a calculated column. I thought of using some event like afterInsertRow, but even with no event it moves the column data by one because the XML file is only 3 columns instead of four. So my Total column now has the data from Notes I did add a fake column to the php file, but why should I have to do that? Thanks

url:'./calctotal',
datatype: 'xml',
mtype: 'GET',
colNames:['Inv No', 'Amount','Tax','Total'm 'Notes'],
colModel :[ 
  {name:'invid', index:'invid', width:55}, 
  {name:'amount', editable: false, index:'amount', width:80, align:'right'}, 
  {name:'tax', index:'tax', width:80, align:'right'}, 
  **{name:'total', index:'total', width:80, align:'right'},**
  {name:'notes', index:'notes', width:80, align:'left'}

],

推荐答案

在jqGrid中实现虚拟列"的最有效方法是使用

The bast way to implement "virtual columns" in jqGrid is the usage of the custom formatter. For example

{name:'amount',index:'amount',width:70, formatter:'currency', align:'right'},
{name:'tax',index:'tax',width:50, formatter:'currency', align:'right'},
{name:'total',index:'total',width:60, align:'right',
 formatter:function(cellvalue, options, rowObject) {
     var amount = parseInt(rowObject.amount,10),
         tax = parseInt(rowObject.tax,10);
     return $.fmatter.util.NumberFormat(amount+tax,$.jgrid.formatter.currency);
 }}

使用自定义格式化程序的主要缺点是您在内部使用了完全格式化.调用方法$.fmatter.util.NumberFormat可以帮助我们简化工作.

The main disadvantage of the usage of the custom formatter is that you use make full formatting inside. The call of the method $.fmatter.util.NumberFormat can help us to simplify the work.

如果使用远程数据类型(datatype: 'xml'datatype: 'json'),则服务器负责数据排序.因此,服务器不仅应该能够对真实"数据字段进行数据排序,而且还能够对虚拟"列进行数据排序.我们使用上面的index:'total'.因此,如果用户单击总计"列的标题,将发送到服务器的sidx参数将是total.因此服务器应该能够生成按total排序的数据.

If you use remote datatype (datatype: 'xml' or datatype: 'json') the server is responsible for data sorting. So the server should be able to sort the data not only for the "real" data field but for the "virtual" columns also. We use index:'total' above. So if the user click on the header of the 'Total' column the sidx parameter which will be send to the server will be total. So the server should be able to produce the data sorted by the total.

如果您使用本地数据,则可以使用sorttype作为实现排序的功能:

If you use local data you can use sorttype as the function to implement the sorting:

{name:'amount',index:'amount',width:70, formatter:'currency', sorttype:'number',
 align:'right'},
{name:'tax',index:'tax',width:50, formatter:'currency', sorttype:'number',
 align:'right'},
{name:'total',index:'total',width:60, align:'right',
 formatter:function(cellvalue, options, rowObject) {
     var amount = parseInt(rowObject.amount,10),
         tax = parseInt(rowObject.tax,10);
     return $.fmatter.util.NumberFormat(amount+tax,$.jgrid.formatter.currency);
 },
 sorttype:function(cellvalue, rowObject) {// like for sorttype:'number',
     var amount = parseInt(rowObject.amount,10),
         tax = parseInt(rowObject.tax,10);
     return amount+tax;
 }}

此处查看演示.

这篇关于如何在jqGrid中创建非数据库列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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