How to select n number of column when selectAll button is pressed?

How to select n number of column when selectAll button is pressed?

salman_malyksalman_malyk Posts: 5Questions: 2Answers: 0

I am using to datatable select plugin and when user presses selectAll button i want to select only n number of records which i've specified.

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 20,145Questions: 26Answers: 4,736

    If you are referring to this example you can use one the row-selector options to select only those rows you wish. If you still need help please provide more information about "i want to select only n number of records which i've specified.".

    Kevin

  • salman_malyksalman_malyk Posts: 5Questions: 2Answers: 0


    Here's my custom button that i created, It does work but it takes too much time because it's iterating each entries until max limit is reached.
    Hope this code will explain what i am trying to do.

  • colincolin Posts: 15,118Questions: 1Answers: 2,583
    Answer ✓

    You can refactor that code to make it more efficient:

    1. You're counting the rows on each iteration - you only need to do it once and then increment the count yourself.
    2. You keep going through the loop even when the max value is reached - you can break out by returning false

    This is the code from this example:

      var selectedRows = table.rows({selected:true}).count();
      table.rows().every(function(i) {
        if (max > selectedRows) {
          this.select();
          selectedRows++;
        }
        else {
          return false;
        }    
      })
    

    Colin

  • salman_malyksalman_malyk Posts: 5Questions: 2Answers: 0

    Yes thank you @colin that worked. :)

Sign In or Register to comment.