Search code examples
javascripttabulator

Select a row programmatically using tabulator selectRow method


I am using tabulator to create tables on my website. I can select rows by clicking on them and I can select all rows using the tabulator.selectRow() method.

According to the documentation:

To select a specific row you can pass the any of the standard row component look up options into the first argument of the function.

I have seen this a few times but there is no working example. Does anybody know how the row component look up options need to be provided?

Let's say I have rows which have a name field.

I want to select the row where name == 'dennis'.

The documentation suggests that I can pass a lookup option in the selectRow() argument. There is just no example or any indication to expected syntax for the argument.

I currently have this working like so which does not seem to be most intuitive way.

table.getRows().forEach(row => {
  if (row.getData().name == 'dennis') row.toggleSelect();
});

Or like so:

params.layer.tableView.table.getRows()
    .filter(row => row.getData().name == 'dennis')
    .forEach(row => row.toggleSelect());

Solution

  • I got there in the end with help via github. #1749

    The bit which cleared this up for me was this:

    Any function that takes a component as an argument will also attempt to find that component based on the value provided if it is not a component itself.

    Here as an example to select my row.

    table.selectRow(table.getRows().filter(row => row.getData().name == 'Dennis'));