Datatables Select via API and Mouseclick (Bug?)

Datatables Select via API and Mouseclick (Bug?)

FloKazFloKaz Posts: 2Questions: 1Answers: 0

Hi,

I already fixed my Problem but i wanted to share my Information about it.

Maybe its a Bug or it was intentional but somehow when i select something via API of the Select-Plugin

table.row(identifier).select()

it doesnt seem to update the internal Values for last selected Rows.

You can test this scenario directly here on the website
https://datatables.net/extensions/select/examples/initialisation/simple.html

If you open the Console and just enter

$('#example').DataTable().row('#example > tbody > tr:nth-child(5)').select();

after that Shift+MouseClick any Row and the Selection starts from the Top of the table instead of the last clicked Row.

I Fixed my problem already with manually updating the internal values when selecting/deselecting Rows via the API.

and here is what helped me. Maybe it will also help someone else

/// on deselect
tableObj.settings()[0]._select_lastCell = null;
tableObj.rows().deselect();

// on selection
tableObj.row(rowSelector).select();
tableObj.settings()[0]._select_lastCell = tableObj.cell(rowSelector+' td:eq(0)').index();

best regards

Answers

  • allanallan Posts: 62,338Questions: 1Answers: 10,228 Site admin

    The API and mouse click to not share any information about the shift key. The shift key is only used when the mouse is used to select rows. Using the API does not effect the behaviour of the shift key at all.

    Allan

  • FloKazFloKaz Posts: 2Questions: 1Answers: 0

    Well ok if it is intentional then its OK. Just to Explain my Usecase.

    I use 2 Tables. One Table Showing suspicious Rows in the other Table and when i Click one row in Table 1 it jumps to the correct position of Table 2 and selects the row (via API). The user is now able to maybe delete this row but also has the ability to shift click another row for a range of rows to delete. In this case it would be really nice if the api shares the same behaviour like a userinteraction.

    But anyway how i said i could solve my problem without changing any api related functions and therefor its fine for me and i just wanted to share this information for others with similar problems :)

    and BTW thanks for your great work :) really love your datatables :)

    brest regards

This discussion has been closed.