Column color when reload ajax

Column color when reload ajax

andrii.radkovskiiandrii.radkovskii Posts: 20Questions: 0Answers: 0

Hello All, Help me please.
I'm having trouble rebooting AJAX, when I restart ajax, then the color of the column disappears.
Maybe, someone knows how to solve this problem?
My render code.
Video - https://drive.google.com/file/d/1uXXtXEIkoXw-u4MSZ4RY7WsOVcgyrD0D/view?usp=sharing
My full code - https://pastebin.com/iFUwRsV1

            "render": function (data, type, full, meta) {
                var cellText = $(data).text();
                if (type === 'display' && (cellText == "Так" || data == 'Так')) {
                    var rowIndex = meta.row + 1;
                    var colIndex = meta.col + 1;
                    $('#table tbody tr:nth-child(' + rowIndex + ') td:nth-child(' + colIndex + ')').css('background-color', '#ff9797').css('color', '#ffffff');
                    return data;
                } else {
                    return data;
                }
            }

Replies

  • kthorngrenkthorngren Posts: 21,327Questions: 26Answers: 4,949
    edited November 2018

    Interesting demo, thanks,. My guess is that the rowIndex and/or colIndex are not what you expect them to be during reload. Hard to say though without seeing it in action. You could try some console.log statements in your render function to see what's happening.

    However using columns.render is not intended for manipulating the tr elements. You should use createdRow or rowCallback or columns.createdCell for this.

    Kevin

  • andrii.radkovskiiandrii.radkovskii Posts: 20Questions: 0Answers: 0
    edited November 2018

    @kevin Thanks!!! I used this code! Maybe someone else will come in handy.
    live.datatables.net/yiceculu/1/edit

            "columnDefs": [{
                "targets": 2,
                "createdCell": function (td, cellData, rowData, row, col) {
                    if (cellData == "Так") {
                        $(td).css('background-color', '#ff9797').css('color', '#ffffff');
                    }
                }
            }]
    
This discussion has been closed.