Jqgrid generate xml from data grid task

I have a question regarding the question: enter a description of the link here I added 'datatype: "local"' to my grid, and it worked, I got xml, but it included the checkbox column that I have in the grid inside it. 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>

how can i include checkbox values ​​inside the created xml? and if this is not possible, is there any other way to get xml from my data inside the grid?

Thanks in advance.

+1
source share
1 answer

I believe that your problem will be resolved if you add custom unformatter to the custom formatter checkboxFormatter that you are currently using.

unformatter jqGrid - . jqGrid, unformatter chackbox.

: . , , , , . chechboxes, . , , data jqGrid . , data .

, : 1) unformatter myunformatfunc

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

2) jQuery("#confirm_payment").jqGrid('getRowData') ( unformatter) jQuery("#confirm_payment").jqGrid('getGridParam','data'). , , , .

/ " XML". XML: 'getRowData' getGridParam('data'). , getRowData .

+1

Source: https://habr.com/ru/post/1788268/


All Articles