0

我遇到了一个问题,即 csv 导出未导出使用 fnRowCallback 设置的值,我尝试查看正交但似乎不想工作。

我的按钮代码如下:

buttons: [
       'selectNone',
       'selectAll',
       {
           extend: 'csv',
           title: 'Data export',
           exportOptions: {
               columns: colArr, rows: { selected: true }
           }
       }],

我在页面加载时动态生成列,因为这不是固定的:

 var Columns = [
    { "data": "Name" },
    { "data": "EmployeeNum", "sClass": "text-center" },
    { "data": "DateStartedS", "sClass": "text-center" },
    { "data": "DateCompletedS", "sClass": "text-center" },

];

for (var a = 0; a < QuestionLength; a++) {
    Columns.push({ "data": "ID", "sClass": "text-center" });
}

Columns.push({ "data": "ID", "sClass": "text-center" });

然后一旦完成,我使用 fnRowCallback 从方法中获取值:

fnRowCallback: function (nRow, aData, iDisplayIndex, iDisplayIndexFull) {

        var QuestionColumns = $("#tblPollsReport thead td.trquestion");;

        $.each(QuestionColumns, function (idx, item) {

            var QuestionID = $(item).attr("data-questionid");

            var Result = FindAsnwer(QuestionID, aData["QuestionAsnwers"]);
            debugger;
            var QNum = idx + 4;
            //$('td:eq(' + QNum + ')', nRow).val("Hallo");
            $('td:eq(' + QNum + ')', nRow).html(Result);
        })
        //Actions
        var ActoinHtml = '<div class="btn-group">';
        ActoinHtml += '<button onclick="DeletePollUser(' + aData["ID"] + ')" title="Delete" class="btn btn-xs btn-danger js-tooltip"><i class="fa fa-times"></i></button>';
        ActoinHtml += '</div>';

        var ActionCol = (4 + QuestionLength);

        $('td:eq(' + ActionCol + ')', nRow).html(ActoinHtml);
    },

但是,一旦我导出它,它就会使用我在添加到列时添加的原始值,而不是我在 fnRowCallback 中设置的值。

任何帮助,将不胜感激。

4

1 回答 1

0

好的,我最后成功了

我修改了列部分以包含以下内容:

for (var a = 0; a < QuestionLength; a++) {
    Columns.push({
        "data": "ID", "sClass": "text-center", render: function (data, type, row, colinfo) {

            if (type === 'export') {
              //Any logic you would like to overide with
            } else {
                return data;
            }

        }
    });
}
于 2018-03-21T21:44:57.940 回答