簡體   English   中英

在復選框選擇上將jqgrid數據導出到excel

[英]export jqgrid data into excel on checkbox selection

我已經從MVC控制器綁定了jqGrid,下面是我的jqgrid代碼。 我想將選定的復選框行數據導出到csv中,我已經遍歷了所有代碼,但是每個代碼都提供了示例本地數據,但是我將服務器綁定到jqGrid,因此當我在jqGrid中選擇復選框行並單擊“導出”按鈕時整行應導出到csv,有人可以解決嗎?

$('#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");
            }
        }

    });

為了澄清,單擊時必須有任何按鈕,csv將從所選復選框生成。 如果是這樣,則遍歷網格數據以篩選出選中的行。 您可以在觸發按鈕事件時輕松遍歷網格數據。 根據結果​​數據創建csv。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM