Select rows limits?

Select rows limits?

19kash8819kash88 Posts: 6Questions: 0Answers: 0
edited May 2013 in General
Is there a way to select maximum number of rows per table instead of doing as many as you want? Using this http://www.datatables.net/release-datatables/examples/api/select_row.html

Replies

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin
    There isn't a built in way of doing it, but you could add a bit of logic to the selection event handler which would not select the row clicked on if there are a certain number already selected.

    Allan
  • 19kash8819kash88 Posts: 6Questions: 0Answers: 0
    @allan - Thanks for your response. This is a what I came up with. So far it is working great :)

    [code]

    /* Add/remove class to a row when clicked on */
    $('.dataGrid tbody tr').bind('click', function() {
    var $_this, $_table, $_selected, i, thisRow, thisClass, tableRows = $(".dataGrid tbody tr"), trLen;
    trLen = tableRows.length;
    // Get the row that's just been clicked
    $_this = $(this);
    // Get its parent table
    $_table = $_this.parents('table').first();
    // Get all of the rows within it that have been selected
    $_selected = $_table.find('tr.row_selected');
    // If the row is already selected
    if ($_this.is('.' + ROW_SELECTED_CLASS)) {
    // Remove the selection
    $_this.removeClass(ROW_SELECTED_CLASS);
    // Remove class disabled class
    $(".dataGrid tbody tr").removeClass('disabled');
    } else {
    // If it is not already selected
    // If the number of already selected rows is less than the max
    if ($_selected.length < MAX_ROWS) {
    // Add the selection
    $_this.addClass(ROW_SELECTED_CLASS);
    }
    //Add disabled class when max selected
    if($_selected.length === MAX_ROWS - 1) {
    for(i=0;i
This discussion has been closed.