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

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

问题描述

我对以下问题有疑问:在此处输入链接描述 我在网格中添加了数据类型:本地"",它可以正常工作,我得到了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"?>\n<rows>\n' +
                          xmlJsonClass.json2xml (dataFromGrid, '\t') + '</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?

先谢谢了.

推荐答案

我想您的问题将得到解决,因为您还包括了您当前使用的自定义格式化程序 checkboxFormatter.

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

没有格式化程序,jqGrid无法从网格读取任何值.查看 jqGrid的源代码用于标准chackbox类型的unformatter.

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.

已更新:您的代码将成功导出数据.您可能遇到的另一个问题.您包括具有启用复选框的自定义格式化程序,而不是由预定义的复选框格式化程序创建的禁用的检查框.如果用户更改某些复选框的状态,则必须手动更新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)将未格式化程序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天全站免登陆