Значение ячейки обновления Datatables не отображается - PullRequest
0 голосов
/ 11 декабря 2018

Я хотел бы знать, как изменить значение ячейки в Datatables.Мне нужно установить первую ячейку последней строки со значением rows.count ().

Вот моя функция для создания Datatables:

function callForStepBoxes(){
    flow.steps = [];
    flowChartJSON = new Array();
    if(!typeof currentFlowsTable === 'undefined' || currentFlowsTable != null){
        $('#flowsTable').DataTable().ajax.url(restURI + 'orch/search/operations/'+flow.name).load();
        $('#flowsTable').DataTable().ajax.reload();
    } else {
        currentFlowsTable = $('#flowsTable').DataTable({
            responsive: true,
            columnDefs: [
                { responsivePriority: 1, targets: 0 },
                { responsivePriority: 2, targets: 4 },
                { responsivePriority: 3, targets: 2 },
                { responsivePriority: 4, targets: 3 },
                { responsivePriority: 5, targets: 4 },
                { responsivePriority: 6, targets: 5 }
            ],
            ajax: {
                "url": restURI + 'orch/search/operations/'+flow.name,
                "contentType": "application/json",
                "type": "GET",
                "data": null,
            },
            order: [0, 'desc'],
            scrollCollapse: true,
            scrollX: false,
            aLengthMenu: [
                [10, 25, 50, 100, -1],
                [10, 25, 50, 100, "All"]
            ],
            iDisplayLength: -1,
            "columns": [
                {"data": "ROWID", "defaultContent": "", "sClass": "displayNone"},
                {"data": "STEP", "defaultContent": "", "sClass": "text-center limitedWidth"},
                {"data": "OPERATION_NAME", "defaultContent": "", "sClass": "text-center limitedWidth"},
                {"data": null, "defaultContent": "<input type='number' class='flowTimeoutValue'/>", "sClass": "text-center limitedWidth"},
                {"data": null, "defaultContent": "<input type='number' class='flowLimitValue'/>", "sClass": "text-center limitedWidth"},
                {"data": null, "defaultContent": "<input type='checkbox' class='flowActiveValue' checked='false'/>", "sClass": "text-center limitedWidth"},
            ],
            'rowCallback': function(row, data, index) {
                // Retrieve rows.count
                lastStep = currentFlowsTable.data().count();
                // Retrieve last row
                lastRow = currentFlowsTable.row(':last').data();
                // Set the value
                lastRow.STEP = lastStep;
                currentFlowsTable.row(':last').data().STEP = lastStep;
            },
            'drawCallback': function(settings){
                createNodesAndEdges(flowChartJSON);
            }
        });
    };
}

Я получаю rows.count(), я извлекаю последнюю строку и устанавливаю значение, но оно не работает.Что я делаю неправильно ?Спасибо!

Ответы [ 2 ]

0 голосов
/ 11 декабря 2018

Я нашел решение.Я добавил класс в столбец и хочу обновить первую ячейку, а затем проверяю, пусто ли значение ячейки.

function callForStepBoxes(){
    flow.steps = [];
    flowChartJSON = new Array();
    if(!typeof currentFlowsTable === 'undefined' || currentFlowsTable != null){
        var flowTable = $('#flowsTable').DataTable().ajax.url(restURI + 'orch/search/operations/'+flow.name).load();
        flowTable.ajax.reload();
    } else {
        currentFlowsTable = $('#flowsTable').DataTable({
            responsive: true,
            columnDefs: [
                { responsivePriority: 1, targets: 0 },
                { responsivePriority: 2, targets: 4 },
                { responsivePriority: 3, targets: 2 },
                { responsivePriority: 4, targets: 3 },
                { responsivePriority: 5, targets: 4 },
                { responsivePriority: 6, targets: 5 }
            ],
            ajax: {
                "url": restURI + 'orch/search/operations/'+flow.name,
                "contentType": "application/json",
                "type": "GET",
                "data": null,
            },
            order: [0, 'desc'],
            scrollCollapse: true,
            scrollX: false,
            aLengthMenu: [
                [10, 25, 50, 100, -1],
                [10, 25, 50, 100, "All"]
            ],
            iDisplayLength: -1,
            "columns": [
                {"data": "ROWID", "defaultContent": "", "sClass": "displayNone"},
                {"data": "STEP", "defaultContent": "", "sClass": "text-center limitedWidth stepCell"},
                {"data": "OPERATION_NAME", "defaultContent": "", "sClass": "text-center limitedWidth"},
                {"data": null, "defaultContent": "<input type='number' class='flowTimeoutValue'/>", "sClass": "text-center limitedWidth"},
                {"data": null, "defaultContent": "<input type='number' class='flowLimitValue'/>", "sClass": "text-center limitedWidth"},
                {"data": null, "defaultContent": "<input type='checkbox' class='flowActiveValue' checked='false'/>", "sClass": "text-center limitedWidth"},
            ],
            'rowCallback': function(row, data, index) {
                // Set the STEP for ARCHIVE operation
                lastStep = currentFlowsTable.data().count();
                if($(row).find('.stepCell').text() === "") {
                    $(row).find('.stepCell').append(lastStep);
                }
            },
            'drawCallback': function(settings){
                createNodesAndEdges(flowChartJSON);
            }
        });
    };
}
0 голосов
/ 11 декабря 2018

пожалуйста, попробуйте изменить ниже.

var flowTable = $('#flowsTable').DataTable().ajax.url(restURI + 'orch/search/operations/'+flow.name).load();
        flowTable.ajax.reload();
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...