rows.select,rows.deselect api does not work. Is there an extension or js file that needs to be added

rows.select,rows.deselect api does not work. Is there an extension or js file that needs to be added

chitachita Posts: 33Questions: 12Answers: 2
$(".selectAll").on( "click", function(e) {
    if ($(this).is( ":checked" )) {
      $('#example').rows({page:'current'}).select();
      console.log('select');    
    } else {
      $('#example').rows({page:'current'}).deselect();
      console.log('deselect'); 
    }
  });

I've tried using a new code that says it's valid by looking around the example of full checkbox selection in the forum, but it doesn't work. What's the reason?

This question has an accepted answers - jump to answer

Answers

  • chitachita Posts: 33Questions: 12Answers: 2

    The current Uncaught TypeError: $(...).rows is not a function error.

  • colincolin Posts: 15,237Questions: 1Answers: 2,599

    You need to reference the DataTables object first:

    $('#example').DataTable().rows({page:'current'}).select();
    

    and likewise for the row().deselect(),

    Colin

  • chitachita Posts: 33Questions: 12Answers: 2
    edited September 2023

    If you change to that syntax, a new table is created in the space where the table was located, and the Uncaught TypeError: $(...).DataTable(...).rows(...).select is not a function error remains. Is there a css or js file or npm package that I need to add to use that function?

  • chitachita Posts: 33Questions: 12Answers: 2

    There was a problem with the table object declaration. After the modification, I applied the code you told me, so it works normally. However, the check box is not active, although the entire row is selected. What should I do? The row checkbox implementation used this example.

  • allanallan Posts: 63,290Questions: 1Answers: 10,428 Site admin
    Answer ✓

    The example you linked to doesn't use the checkboxes for row selection - it uses it to indicate the value of a field and to let the user change that value without entering into an edit mode.

    This example demonstrates Selects` checkbox option, and this example shows it being used with Editor.

    Allan

Sign In or Register to comment.