Pilot the row selection (needed for a "rows navigation by keyboard plugin)

Pilot the row selection (needed for a "rows navigation by keyboard plugin)

lzzlucalzzluca Posts: 9Questions: 0Answers: 0
edited February 2014 in General
Hi!
I am writing a jQuery plugin to navigate the Datatable's rows by keyboard (by up and down arrows) and select them (by pressing the Enter button), as beginning of making the table accessible without the mouse.
The plugin is done but I would like some help about this: to select a row, I just add on it the class "row_selected". The problem is that the single selection could be set up on the datatable (in that case I would reset the previous selection), or the multi selection (in that case I wouldn't reset anything), maybe there is no selection allowed on the datatable!
How I can check with kind of selection is enabled in the datatable (if it is)? Even better, there is a method that I can call, from the datatable, that knows itself which kind of selection is applied and behaves accordingly?
I hope I am not asking something obvious... My previous googling didn't help... :(
Thanks,
Luca

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    > How I can check with kind of selection is enabled in the datatable (if it is)?

    > I just add on it the class "row_selected".

    You are adding the row selected logic in your own code (as your second statement says) - so surely you know which one is being used? Perhaps just store it in a variable?

    Allan
  • lzzlucalzzluca Posts: 9Questions: 0Answers: 0
    Thanks for the answer.
    Well, to be honest I don't know which kind of selection is being used!
    I am confused about that; going on with my trials, I have found these as the best candidates for what I am looking for:

    var cfg = $(myDTSelector).dataTable().fnSettings().oInit;

    var row_selection = cfg.row_selection;
    var selection = cfg.selection;
    var selection_method = cfg.selection_method;

    The curious fact is that once I have found:
    selection === "none"
    selection_method === "row_click"
    row_selection === true
    but I was allowed to select a limitless number of rows on that datatable, even with selection equals to none. How that is possible?

    [quote]
    You are adding the row selected logic in your own code
    [/quote]
    Do you think that is the right way to proceed?

    An alpha of the plugin is available here: https://github.com/lzzluca/dataTableRowNavByKeyb/blob/master/rowNavigation.js

    Thanks for you time,
    Luca
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    It seems like a reasonable way to do it.

    Another option is to use the row selection abilities and API of TableTools, so you don't need to worry about the row selection aspect, you just use the API to know what rows are selected and change the selection if needed.

    > but I was allowed to select a limitless number of rows on that datatable, even with selection equals to none. How that is possible?

    I would need to go through your code to figure it out. I'm afraid I'm rather busy at the moment, so can't do so.

    Allan
  • lzzlucalzzluca Posts: 9Questions: 0Answers: 0
    The TableTools is better... I didn't have the opportunity to explore it as it deserves, I am going to try to add it to the plugin.
    So far, thank you Allan.
    The Datatable rocks and you are always kind to spend your time asking questions.

    Luca
  • jrichviewjrichview Posts: 36Questions: 7Answers: 0

    Luca,
    It turns out I need this very same thing: navigation and single selection of rows via keyboard. This is for accessibility & 508 compliance.

    I looked at TableTools but it did not seem to offer this. What did you end up doing?

  • lzzlucalzzluca Posts: 9Questions: 0Answers: 0
    edited May 2014

    Yep... I think the TableTools doesn't match the need but I am happy if we are wrong and Alan can correct us. Anyway I did this:<br>
    <a href="https://github.com/lzzluca/dataTableRowNavByKeyb">here</a><br>
    It is not something that I consider finished but it is "something": in the repo you can find the plugin to do the job and a demo for it.<br>
    It doesn't seem to work with paginated dataTable: the little I have checked it, it was a mistery! :)<br>
    For anything about the plugin, I think would be nice to continue on the GitHub repo, to get something helpful for other users as well.<br>
    Hope this can help.<br><br>
    Luca

This discussion has been closed.