Finding ids of rows in selected column

Finding ids of rows in selected column

goktuginal41@gmail.comgoktuginal41@gmail.com Posts: 57Questions: 22Answers: 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: 63,687Questions: 1Answers: 10,500 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: 57Questions: 22Answers: 0
    edited July 2022
    $('#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: 21,445Questions: 26Answers: 4,974
    edited July 2022 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.