Select Option to Get All Row Data into a item Object

Select Option to Get All Row Data into a item Object

BeerusDevBeerusDev Posts: 5Questions: 2Answers: 0

Link to test case: https://jsfiddle.net/BeerusDev/on63y9d1/28/

I have a working table that has the select option available. I want to have it so when the .select-checkbox is clicked in any row, I can gather all of that rows data. I have a handler function and nothing is triggering upon click.

Answers

  • kthorngrenkthorngren Posts: 21,341Questions: 26Answers: 4,954

    You have a couple options. One is to use delegated events as shown in this example.

    Better might be to use the select event since you are using the Select Extension. See this example for the recommended way to get selected rows.

    Kevin

  • BeerusDevBeerusDev Posts: 5Questions: 2Answers: 0

    Coming back to this issue, I have the following in a button action function.

    columnDefs: [{
                        orderable: false,
                        className: 'select-checkbox',
                        targets: 0
                    }],
                    buttons: [
                        {
                            text: 'Mark for Delivery',
                            action: function () {
                                const selRowData = preDeliveryTable.row({ Selected: true }).data(); //get the data of the clicked row
                                const workingDocID = selRowData.itemID;
                                console.log(selRowData);
                                console.log(workingDocID);
                                
                            }
                        },
                    ],
                    select: {
                        style: 'os',
                        selector: 'td:first-child'
                    },
    

    When I select the checkbox in a row, no matter which selection I make. It defaults to the first row in the table even when I do not select that row?

    Working on updating the test case now.

  • BeerusDevBeerusDev Posts: 5Questions: 2Answers: 0
    edited January 2023
  • kthorngrenkthorngren Posts: 21,341Questions: 26Answers: 4,954

    You have preDeliveryTable.row({ Selected: true }) with Selected with an upper case S. This should be lower case, for example: preDeliveryTable.row({ selected: true }).

    Kevin

  • BeerusDevBeerusDev Posts: 5Questions: 2Answers: 0

    Wow, that is all it was... Thank you Kevin.

Sign In or Register to comment.