clicking the paging buttons is adding classes to TDs

clicking the paging buttons is adding classes to TDs

profoundhypnoticprofoundhypnotic Posts: 16Questions: 6Answers: 0

Link to test case:
Debugger code (debug.datatables.net):
Error messages shown: n/a
Description of problem:
The last column in my table has the class dt-type-date removed using createdRow. However, when I go through all the pages of the table, and then go back to the first page, that class is added back to the last td. If I close the modal the table is in and open it back up then the class is removed again. There are two pages in my current table, if I click the button to go to the 2nd page the class is still removed but if I click back to the first page, the class is added back. I can click on the arrow or the actual number and the behavior is still the same.

I have this Init for my datatable:

//create the datatable
    dt = jQuery('#modal_table').DataTable({
        destroy: true,
        processing: true,
        data: JSON.parse(modal_data),
        columns: columns,
        order: [[3,'asc']],
        pageLength: 10,
        columnDefs: [
            {className: "dt-head-center",targets: '_all'},
            {className: "dt-center",targets: '_all'},
        ],
        pagingType: "simple_numbers",
        createdRow: function (row, data) {
               setTimeout(function(){
                jQuery(row).find("td:last").removeClass('dt-type-date');
            },10);
        }
    });

This question has accepted answers - jump to:

Answers

  • profoundhypnoticprofoundhypnotic Posts: 16Questions: 6Answers: 0
    edited March 11

    I coudln't reproduce in the datatables js bin so here are some screenshots in hopes they help.
    the first screenshot is going to the 2nd page with the class dt-type-date still removed. The 2nd screenshot is when I click back to the first page. The class dt-type-date is added.

  • kthorngrenkthorngren Posts: 21,790Questions: 26Answers: 5,042
    Answer ✓

    Use DataTable.type() to remove the classname instead of createdRow, for example:

    DataTable.type('date', 'className', '');
    

    See the Types docs for more details.

    Kevin

  • profoundhypnoticprofoundhypnotic Posts: 16Questions: 6Answers: 0

    Thanks for your response Kevin! If I remove the createRow option and use the line you provided above, the first page has the dt-type-date class but if I click to the 2nd page then the class is removed. But then If I go back to the first page the class is back. If I leave the CreatedRow option and the code you supplied, then none of the pages have the class. as long as it works I'm cool just wanted to let you know. thanks for your help !

  • kthorngrenkthorngren Posts: 21,790Questions: 26Answers: 5,042
    Answer ✓

    That code works in this test case without `-option createdRow:
    https://live.datatables.net/cafuhami/1/edit

    There might be another process happening that is causing the class to be added. Possibly the version of Datatables you have is not handling this correctly. Can you update my test case to show the issue?

    Kevin

  • allanallan Posts: 64,142Questions: 1Answers: 10,584 Site admin

    I think there was indeed an old version of DataTables that had this problem. It should be fine in the current release.

    Allan

  • profoundhypnoticprofoundhypnotic Posts: 16Questions: 6Answers: 0

    @kthorngren moving the declaration for type above my initialization solved the issue. Thank you so much!

Sign In or Register to comment.