Multiple selects (2 part question)

Multiple selects (2 part question)

54696d2054696d20 Posts: 75Questions: 18Answers: 0

Hey Guys,

I know I can hold control and select multiple rows. Is there a way around that to where you don't have to hold control?

The table shows the number of rows selected. Is that information put into an array? I've coded below and it works just fine. Just wondering if you have already designed this.

var searchForCheckeds = $("#studentsTab tbody tr.selected").map(function () { var studentID = $(this).find("td").eq(0).html(); return studentID; }).get();

Only problem with this is that I have some hidden columns that have the Row ID (which I actually want). This code only grabs what's on the page.

Thanks again,
Tim

This question has accepted answers - jump to:

Answers

  • colincolin Posts: 15,144Questions: 1Answers: 2,586
    Answer ✓

    Hi @54696d20 ,

    Yep, see this example here,

    Cheers,

    Colin

  • 54696d2054696d20 Posts: 75Questions: 18Answers: 0

    Thanks @colin. What about the second part?

    The table shows the number of rows selected. Is that information put into an array? I've coded below and it works just fine. Just wondering if you have already designed this.

    var searchForCheckeds = $("#studentsTab tbody tr.selected").map(function () { var studentID = $(this).find("td").eq(0).html(); return studentID; }).get();

    Only problem with this is that I have some hidden columns that have the Row ID (which I actually want). This code only grabs what's on the page.

    Thanks again,

    Tim

  • kthorngrenkthorngren Posts: 20,309Questions: 26Answers: 4,770
    Answer ✓

    Colin pointed you to the Select Extension which has API's to both get and set selected rows. You can get the selected rows using the API similar to this:
    https://datatables.net/extensions/select/examples/api/get.html

    Instead of using count() you would use data() to get the data of all the rows selected.

    Kevin

  • 54696d2054696d20 Posts: 75Questions: 18Answers: 0
    edited October 2018

    Ahh.. Thanks @kthorngren . I was using

    .on( 'select', function ( e, dt, type, indexes ) { var rowData = table.rows( indexes ).data().toArray(); }

This discussion has been closed.