jqgrid 从网格数据生成 xml 问题 [英] jqgrid generate xml from grid data problem

查看:16
本文介绍了jqgrid 从网格数据生成 xml 问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对以下问题有疑问:在此处输入链接描述我在网格中添加了 'datatype:"local"' 并且它有效,我得到了 xml,但它确实在其中包含了我在网格中的复选框列.这是我的代码:

I have a question regarding the question: enter link description here I added 'datatype:"local"' to my grid and it worked , i got the xml , but it did include inside of it the checkbox column i have in the grid. this is my code:

  <script type="text/javascript" >

        var MyExportToXml = function (grid)
        {
            var dataFromGrid = {row: grid.jqGrid ('getGridParam', 'data') };
            var xmldata = '<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rows>
' +
                          xmlJsonClass.json2xml (dataFromGrid, '	') + '</rows>';
            alert(xmldata);
        };                                   

        function checkboxFormatter(cellvalue, options, rowObject)
        {
            var _checkbox_name = options.colModel.name;
            var _checkbox_name_id = _checkbox_name + options.rowId;

            cellvalue = cellvalue + "";
            cellvalue = cellvalue.toLowerCase();
            var bchk = cellvalue.search(/(false|0|no|off|n)/i) < 0 ? " checked " : " ";

            return "<input type='checkbox' id='"+_checkbox_name_id+"' onclick="" " + bchk + " value='" + cellvalue + "' offval='no' />"
        }

        function myunformatfunc(cellvalue, options, rowObject)
        {
            alert(cellvalue);
            return cellvalue;
        }

            jQuery("#confirm_payment").jqGrid({
                url:'loadgrid.jsp?type=1',
                datatype: "xml",
                loadonce:true ,
                direction:"rtl",
                height: '100%',
                width: '100%',
                colNames:['test1' , 'test2' , 'test3' , 'test4'],
                colModel:[
                    {name:'test1',xmlmap:'test1', width:18,align:"center",sortable:false ,edittype:"checkbox", formatter: checkboxFormatter ,unformat:myunformatfunc},
                    {name:'test2',xmlmap:'test2', width:18,align:"center",sortable:false ,edittype:"checkbox", formatter: checkboxFormatter ,unformat:myunformatfunc},
                    {name:'test3',xmlmap:'test3', width:80, align:"right",sorttype:"int"},
                    {name:'test4',xmlmap:'test4', width:70, align:"right",sorttype:"int"},
                ],
                xmlReader: {
                      root:"payments",
                      row:"payment",
                      page:"payments>page",
                      total:"payments>total",
                      records:"payments>records",
                      repeatitems:false
                  },
                multiselect: false,
                autowidth: true,
                forceFit: false,
                shrinkToFit: false
            });           
    </script>

如何在创建的 xml 中包含复选框值?如果不可能,是否有另一种方法可以从网格内的数据中获取 xml?

how can i include the checkbox values inside the created xml? and if it isn't possible, Is there another way to get xml from my data inside the grid?

提前致谢.

推荐答案

我想你的问题会得到解决,如果你额外包含 自定义 unformatter自定义格式化程序 checkboxFormatter 你当前使用的.

I suppose that your problem will be solved is you include additionally custom unformatter to the custom formatter checkboxFormatter which you currently use.

如果没有 unformatter,jqGrid 无法从网格中读取任何值.看实现的jqGrid的源码标准密码箱类型的格式化程序.

Without having unformatter jqGrid can not read any value from the grid. Look at the source code of jqGrid which implement unformatter for the standard chackbox type.

更新:您的代码将成功导出数据.您可能遇到的问题是另一个问题.您包括具有 启用 复选框的自定义格式化程序,而不是由预定义的复选框格式化程序创建的禁用 chechboxes.如果用户改变了某个复选框的状态你必须手动更新jqGrid的data参数.因为您不这样做,所以 data 参数将对应于复选框的初始值.

UPDATED: The data will be successful exported by your code. The problem which you probably have is another. You include the custom formatter which has enabled checkboxes instead of disabled chechboxes created by predefined checkbox formatter. In the case if the user change the state of some checkbox you have to update the data parameter of jqGrid manually. Because you not do this, the data parameter will be corresponds to the initial values of the checkboxes.

要解决问题,您应该 1) 将 unformatter myunformatfunc 的代码修复为以下

To fix the problem you should 1) fix the code of your unformatter myunformatfunc to the following

function myunformatfunc(cellvalue, options, rowObject)
{
    return $('input',rowObject).attr("checked") ? "1" : "0";
}

2) 您应该使用 jQuery("#confirm_payment").jqGrid('getRowData') 方法(将使用您的自定义取消格式化程序)而不是 jQuery("#confirm_payment").jqGrid('getGridParam','data').该方法的缺点是它只读取当前页面的数据,但是由于您不使用本地数据分页,所以对您来说没有问题.

2) You should use jQuery("#confirm_payment").jqGrid('getRowData') method (which will use your custom unformatter) instead of jQuery("#confirm_payment").jqGrid('getGridParam','data'). Disadvantage of the method is that it read the data only the current page, but because you don't use local data paging it is not problem for you.

演示上,您可以选中/取消选中一些复选框并点击将数据导出到 XML"按钮.将显示两种不同版本的 XML:一种与 'getRowData' 有关,另一种与 getGridParam('data') 有关.你怎么看,'getRowData'方式给出了复选框的实际值.

On the demo you can check/uncheck some checkboxes and cick the "Export Data to XML" button. Two different version of XML will be displayed: one with respect of 'getRowData' and another with respect of getGridParam('data'). How you can see, the 'getRowData' way gives actual values of the checkboxes.

这篇关于jqgrid 从网格数据生成 xml 问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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