Trying to get get the row IDs using rows().ids()

Trying to get get the row IDs using rows().ids()

jLinuxjLinux Posts: 981Questions: 73Answers: 75
edited October 2015 in Free community support

I was hoping to get just an array of the row IDs specified via rowId, but when I output the array (after selecting a few rows), it logs more details about the array than I need: ["1", "2", "3", context: Array[1], selector: Object, ajax: Object], definitely not sure where its getting ajax from..

Heres the example I have: http://live.datatables.net/qajimusu/1/edit?js,output

This question has an accepted answers - jump to answer

Answers

  • jLinuxjLinux Posts: 981Questions: 73Answers: 75
    edited October 2015

    Whats weird, is when I re-init the DT API via the JS console, it works fine, but when I click on something I have set to output table.rows( { selected: true } ).ids() to the console (Via something like $().on('click', it will show all the extra info, (which, im assuming, is the API)
    http://d.pr/i/1fQzy

    So how do I have it only return the IDs array?

  • jLinuxjLinux Posts: 981Questions: 73Answers: 75

    Im not sure why this would return the API anyways really... I mean if you just need an array of the selected asset IDs, id think throwing the array into the response would hinder things, like in this situation. But then again, maybe im either doing it wrong, or just dont see the use of the API in the return

  • jLinuxjLinux Posts: 981Questions: 73Answers: 75
    edited October 2015

    Bump? :-D

    This is a problem I actually didnt figure out 20 minutes after posting about it, heh

  • allanallan Posts: 61,650Questions: 1Answers: 10,094 Site admin
    Answer ✓

    Use the toArray() method - otherwise you are getting an DataTables API instance (which is what the ajax etc objects are).

    table.rows( { selected: true } ).ids().toArray();
    

    It returns an API instance for consistency with the rest of the API and to support chaning. For example you might want to use map() or each() with it.

    Allan

  • jLinuxjLinux Posts: 981Questions: 73Answers: 75

    Thats awesome! Thanks @allan, you're the man

This discussion has been closed.