Is it possible to hide rows when creating table from CSV file?

Is it possible to hide rows when creating table from CSV file?

MJ79MJ79 Posts: 5Questions: 3Answers: 0

In the same way that columnDefs can make some columns visible TRUE or FALSE, can the same be done for rows? For example, if I have a CSV file with 50 rows of data, can I just show rows 10 to 30?

Answers

  • rf1234rf1234 Posts: 2,984Questions: 87Answers: 421
    edited January 2018

    take a look at this; https://datatables.net/examples/plug-ins/range_filtering

    $.fn.dataTable.ext.search.push allows you to filter rows.

    our use rowCallback
    https://datatables.net/reference/option/rowCallback

  • MJ79MJ79 Posts: 5Questions: 3Answers: 0

    I don't think any of the two examples offer a solution? I need the rows to be hidden when the table initially loads, similar to the way columns can be?

  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947

    You can use the search option to set the initial search.

    Kevin

  • rf1234rf1234 Posts: 2,984Questions: 87Answers: 421
    edited January 2018

    they both do, I can reassure you ...

    Here is an example for the callback

    rowCallback: function (row, data, index) {
            if ( ...condition ... ) {
                $(row).addClass('hideRow');
            }
        }
    

    CSS:

    .hideRow {
       display: none;
    }
    

    Using bootstrap it should even be easier because you don't need any CSS

    rowCallback: function (row, data, index) {
            if ( ...condition ... ) {
                $(row).addClass('hidden');
            }
        }
    

    e.g.

    rowCallback: function (row, data, index) {
            if ( index < 10 || index > 30  ) {
                $(row).addClass('hidden');
            }
        }
    
This discussion has been closed.