Checkbox updates my table on server side

Checkbox updates my table on server side

jlss070893jlss070893 Posts: 7Questions: 2Answers: 0

Hi I am using datatables with serverSide: true
and I have placed a checkbox in the header of the table by means of html, the table is drawn correctly but when clicking on the checkbox it requests the ajax data again and updates the table, I imagine that it is a default event of datatables, and tried delete any event that is related to that checkbox in the header with preventDefault() and it works but doing it with that method does not paint the checkbox box, I don't know if there is any other way to remove the events related to the table, thanks.

my code to disable events:

    $(".dataTables_scrollHeadInner table thead").off('click').on('click', 'input.chk', function (e) {
       
       e.preventDefault()

       $(this).attr("checked", !$(this).attr("checked"));
    });

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,173Questions: 26Answers: 4,923
    edited November 2020

    Here is a starter example with server side processing enabled. Please update it to show the header you are building and the click events you have.
    http://live.datatables.net/bosaboqa/1/edit

    This will be easier for us to help debug the problem.

    EDIT: It looks like you have two headers with orderCellsTop set to move the sorting events to the top header row. The click events for sorting the table is the only thing Datatables adds. Thats why we need to see what you are doing.

    Kevin

  • jlss070893jlss070893 Posts: 7Questions: 2Answers: 0

    Hi Kevin, thanks for replying. If exactly the option orderCellsTop I use it to assign the order events to the first header, I have updated the code here live.datatables.net/bosaboqa/4/edit how is it in my table to see what the problem is, as you can see I add an input type checkbox to the second header through html but when clicking it shows the Proccesing message which indicates that it reloads the data

  • kthorngrenkthorngren Posts: 21,173Questions: 26Answers: 4,923
    Answer ✓

    Looks like you need to make your jQuery selector more specific for the change event. You have this:

    .dataTables_scrollHeadInner table  thead tr:eq(1) th input
    

    The checkbox is an input and the event handler is applied to it also. Change to this:

    .dataTables_scrollHeadInner table  thead tr:eq(1) th input[type="text"]
    

    See the updated example:
    http://live.datatables.net/wimohufo/1/edit

    Kevin

  • jlss070893jlss070893 Posts: 7Questions: 2Answers: 0

    Oh! I did not realize that detail, you are right so it works correctly thank you very much Kevin

This discussion has been closed.