简体   繁体   English

在复选框选择上将jqgrid数据导出到excel

[英]export jqgrid data into excel on checkbox selection

I have bind the jqGrid from MVC controller , below is my jqgrid code . 我已经从MVC控制器绑定了jqGrid,下面是我的jqgrid代码。 I want to export selected checkbox row data to csv , i have gone through all code's but every one providing sample local data, but i am binding from server to jqGrid,so when i select the checkbox rows in jqGrid and click on "Export " button the entire row should export to csv, can anybody have the solution ? 我想将选定的复选框行数据导出到csv中,我已经遍历了所有代码,但是每个代码都提供了示例本地数据,但是我将服务器绑定到jqGrid,因此当我在jqGrid中选择复选框行并单击“导出”按钮时整行应导出到csv,有人可以解决吗?

$('#jQGrid').jqGrid({ $('#jQGrid')。jqGrid({

        search: true,
        multiboxonly: true,
        colNames: ["PayloadCorrelationId", "Export", "Asset", "DateReported", "ErrorType", "Error", "Latitude", "Longitude", "Payloadurl"],

        colModel: [
            { name: 'CorrelationId', jsonmap: 'CorrelationId', hidden: true, width: 2 },
            { name: "", editable: true, edittype: "checkbox", width: 45, sortable: false, align: "center", formatter: "checkbox", editoptions: { value: "1:0" }, formatoptions: { disabled: false } },
            { name: 'Device', jsonmap: 'Device', width: 60 }, { name: 'DateReported', jsonmap: 'DateReported', width: 100 },
              { name: 'ErrorType', jsonmap: 'ErrorType', width: 85 },
       { name: 'Error', jsonmap: 'Error', width: 140 },
       { name: 'Latitude', jsonmap: 'Latitude', width: 80 }, { name: 'Longitude', jsonmap: 'Longitude', width: 80 },
       { name: 'Payloadurl', jsonmap: 'Payloadurl', width: 180, formatter: 'link' }],

        cellEdit: true,
        pager: jQuery('#divpager'),
        rowList: [5, 20, 50, 100],
        rowNum:5,
        sortorder: "desc",
        datatype: 'json',
        width: 900,
        height: 'auto',
        viewrecords: true,           
        mtype: 'GET',
        gridview: true,
        loadonce: true,
        url: '/DataIn/DataInSearchResult/',

        emptyrecords: "No records to display",
        onSelectRow: true,
        onSelectRow: function (id, status) {
            var rowData = jQuery(this).getRowData(id);
            configid = rowData['CorrelationId'];
            alert(configid);
            // Add this    
            var ch = jQuery(this).find('#' + id + ' input[type=checkbox]').prop('checked');
            if (ch) {
                jQuery(this).find('#' + id + ' input[type=checkbox]').prop('checked', false);
            } else {
                jQuery(this).find('#' + id + ' input[type=checkbox]').prop('checked', true);
            }
            // end Add
            rowChecked = 1;
            currentrow = id;
        },
        loadComplete: function () {
            var ts = this;
            if (ts.p.reccount === 0) {
                $(this).hide();

            } else {
                $(this).show();                    
                $("#lblTotal").html($(this).getGridParam("records") + " Results");
            }
        }

    });

Just to clarify, There must be any buttons on clicking which the csv will generate from the selected check box. 为了澄清,单击时必须有任何按钮,csv将从所选复选框生成。 If it is so then loop through the grid data to filter out checked rows. 如果是这样,则遍历网格数据以筛选出选中的行。 You can loop through the grid data easily on firing the button event. 您可以在触发按钮事件时轻松遍历网格数据。 Based on the resultant data create the csv. 根据结果​​数据创建csv。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM