Click here to Skip to main content
15,566,394 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Please let me know, where I'm going wrong.
I have a button and on its click , it calls 'GetSelectedRecords()' , where im trying to fetch the multiple selected row values.

my script code below

function GetSelectedRecords() {    
 var table = $('#gridview').DataTable();            
            $(this).toggleClass('selected');          
            var AllData = [];            
            $('.selected').each(function () {            
                //alert("Into loop");            
                var pos = table.row('.selected').index();            
                var row = table.row(pos).data();           
                AllData.push(row);        
            });            
            }           


What I have tried:

I have also tried using like below
<pre>$('.selected').each(function (i,v) {            
                var pos = table.row('i').index(); 

and selected two rows in the grid, it returns me the first row value of the grid twice, instead of selected rows values.

also tried the below code
$('.selected').each(function (ind) {            
   //alert("Into loop");            
   var row = table.row(ind).data(); // use ind directly as position       
   AllData.push(row);        
}); 

and selected 2 rows in the grid , in alert it gives me some random 2 different row number , which are also present in the grid, but not selected value rows.
Posted
Updated 21-Apr-21 4:23am

1 solution

You seem to be trying things at random, without reading the documentation.
rows()[^]
row-selector[^]

Try:
JavaScript
var allData = $('#gridview').DataTable().rows(".selected").data().toArray();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900