checked:true and selected: true is returning all rows, checked or not

checked:true and selected: true is returning all rows, checked or not

stingraestingrae Posts: 6Questions: 1Answers: 0

Hi,

I've searched this forum and looked at all the examples, but cannot get this to work.

I've got the first column of my datatable populated by checkbox (as per the example in the documentation), and it's looking good. The problem is when I call the following function to get the selected/checked rows.

Is there something I'm missing? I've copied a few of the examples and they're all returning all the rows, not just the checked/selected ones.

            var table = $('#ddTable').DataTable();
            var dataTableRows = table.rows({ selected: true }).data().toArray();
            var arrTableSelectedRowsRendered = [];
            for (var i = 0; i < dataTableRows.length; i++)
            {
                alert(i);
                // more stuff here
            }

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 20,269Questions: 26Answers: 4,765

    This example is doing something similar:
    http://live.datatables.net/cekoqazu/1/edit

    Can you update the example or provide a link to your page or a test case replicating the issue? This will allow us to see exactly what you have so we can help debug.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

  • stingraestingrae Posts: 6Questions: 1Answers: 0

    Hi Kevin,

    I just tried, but am getting an error saying "Body is 11140 characters too long.". Is there anyway I can attach it?

  • kthorngrenkthorngren Posts: 20,269Questions: 26Answers: 4,765

    The goal of a test case is to reduce it down to just the code needed to replicated the issue, The full solution is typically not needed and makes it harder for us to go through. Reduce the dataset down to a few rows and provide only the code needed to see the problem.

    Kevin

  • stingraestingrae Posts: 6Questions: 1Answers: 0

    Yep, agree and have done it. But got a message saying it needs to be appoved.

  • kthorngrenkthorngren Posts: 20,269Questions: 26Answers: 4,765
    edited December 2019

    Sounds like you are trying to post code directly into the thread. It must of hit the forum's spam filter. You can post your code here for us to look at but if something doesn't standout as an issue then we will ask again for a running test case as described here:
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

  • colincolin Posts: 15,142Questions: 1Answers: 2,586

    That's a lot of code to look through. As Kevin said, can you minimise the code as much as possible, and create a test case that demonstrates the issue. A test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

  • stingraestingrae Posts: 6Questions: 1Answers: 0

    Hi Colin and Kevin. Yes, sorry. I acknowledge the first one there is way too long. I'm trying to find a way to delete it but don't think I can.

    As for making the test case, I'm not sure how to as the data in my case comes from the Model.

  • kthorngrenkthorngren Posts: 20,269Questions: 26Answers: 4,765

    Start here:
    http://live.datatables.net/

    In the HTML table adjust the table to match a sample of your data. You may be able to view the source of your page and copy a few rows of the table into the JS Bin. Then copy your JS code into the Javascript tab. Make sure your example works and provide the steps needed to show the issue.

    Alerts don't work very well in the JS Bin environment. You may want to use console.log instead.

    If you need help with getting the test case going let us know.

    Kevin

  • stingraestingrae Posts: 6Questions: 1Answers: 0

    Hi Colin and Kevin,
    It's ok, I've got a solution by adding in normal checkboxes and reading those.
    Thank you so much for trying to help. At least next time I know not to submit so much code ... I'd like to delete those large posts if I can - is there a way I can contact a mod to do it?
    Cheers.

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

    Done :)

  • stingraestingrae Posts: 6Questions: 1Answers: 0

    Thanks Colin :)

  • DiegoGoDiegoGo Posts: 1Questions: 0Answers: 0
    buttons: [{
                    text: 'Seleccionar Silos',
                    action: function() {
                        var data = taable.rows(.selected).data().toArray();
                        console.log(data)
                    }
                }],
    

    you only can put the class .select, because is the class to add at rows...
    sorry I don't speak English :(

This discussion has been closed.