rubanraj54 / vue-bootstrap4-table

Advanced table based on Vue 2 and Bootstrap 4 ⚡️
MIT License
220 stars 58 forks source link

How do i explicitly target and tick a specific row when adding an dynamic element to a an empty row.? #35

Closed chenxingyu9 closed 5 years ago

chenxingyu9 commented 5 years ago

Eg: I have 5 items already in the table but I wanted to target row 2 or multiple rows ticked explicitly without clicking the row using id or other reference? Thanks.

rubanraj54 commented 5 years ago

Hi @chenxingyu9 ,

Currently, this option is unavailable. But this is a valid request because in some scenarios users want to show the table with preselection.

I will consider this as a feature request and try to implement this on the upcoming release. If you've any other suggestions on how this could be done, please comment here.

Cheers, Ruby.

rubanraj54 commented 5 years ago

Hi @chenxingyu9

Now you can target a specific row using data-id attribute attached with all the <tr> element.

You can specify the uniqueId in the column configuration which you want to use for data-id attribute.

Example:

columns: [{
        label: "id",
        name: "id",
        sort: true,
        uniqueId: true,
        visibility: true
    },
    ...
]

Now your row will have the data-id attribute with the id value from the given data.

Screenshot from 2019-04-22 14-25-17

Then, you can trigger a click event on the specific rows to select.

Example one:

$('[data-id="17"] .vbt-checkbox').click()

Example two:

If your table doesn't have checkbox but only row selection you can use,

$('[data-id="17"]').click()

Cheers, Ruby.