Finding ids of rows in selected column

Finding ids of rows in selected column

goktuginal41@gmail.comgoktuginal41@gmail.com Posts: 23Questions: 11Answers: 0

Hello everyone,

I made a design that performs crud operations on Django FW. I want to select a column and edit the values in that column all in one. I think, I need to keep the row ids of the rows in selected column within an array. Any ideas? Thank you.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 56,837Questions: 1Answers: 9,033 Site admin

    If a column is selected, then you just need the row ids of all rows in the table. rows().ids() will do that.

    Allan

  • goktuginal41@gmail.comgoktuginal41@gmail.com Posts: 23Questions: 11Answers: 0
    edited July 26
    $('#example tbody').on('click', 'tr', function () {
                $(this).toggleClass('selected');
            });
    
            $('#button').click(function () {
                alert(table.rows('.selected').data().length + ' row(s) selected');
               ** console.log(table.rows('.selected').ids());**
            });
    

    When I change console.log part below, I get those results. I just need to reach the dict and get the ids. I have multiple select row operation.

    console.log(table.rows('.selected').data().pluck(0).toArray());
    

    Result: B ["undefined"]

    console.log(table.rows('.selected').data()[0]);
    

    Result: {id: 15, p_id_s: "V3A", reception_date: "2022-07-05", hospital_date: "2022-07-15", culture: "LJ", …}

    console.log(table.rows('.selected').ids());
    

    Result: B ["undefined"]

    console.log(table.rows('.selected').data()[0].id);
    

    Result: 15

    But it does not work for multiple select that I want to keep all ids in an array. Do you know how to fix it? Thank you.

  • kthorngrenkthorngren Posts: 16,780Questions: 25Answers: 3,972
    edited July 26 Answer ✓

    Are you using the rowId option to define the column containing the id's?

    Looks like your data is using arrays, since you have .pluck(0). Try setting the rowId to the column index for rows().ids() to work.

    Kevin

Sign In or Register to comment.