Get selected rows in client side of a filtered Grid

Hello.

I have a Grid control, with a checkbox column and with FilterType="Excel" option.

I need to fill a JavaScript array with all celll values of the selected rows in the grid.

I was using this code (as seen here: https://www.syncfusion.com/kb/7624/how-to-get-selected-records-from-all-page-in-multi-checkbox-feature)





This works great if the user DO NOT fileter the Grid. If you filter the grid using the Excel filter type and you check the first row in the result, after executing the code you always get the first row in the grid, not in the filtered resoluts.

I think the getRecords function doesn't work with filtered rows.


Any help?


Thanks



3 Replies

MS Mani Sankar Durai Syncfusion Team January 5, 2018 11:32 AM UTC

Hi Eligio, 

Thanks for contacting Syncfusion support.  

We have analyzed your query and found that you would like to get the filtered records which are selected from all pages.  
Based on your requirement we have prepared a sample that can be downloaded from the below link 
In this sample we have get the filtered records which is selected from all pages in grid.  
Please refer the code example 
<input type="button" value="Records" onclick=" onClick()" /> 
   <ej:Grid ID="Grid" runat="server" AllowPaging="True" AllowFiltering="true"> 
... 
       <FilterSettings FilterType="Excel"></FilterSettings> 
         <Columns> 
... 
              </Columns> 
    </ej:Grid>    
    <script type="text/javascript"> 
        function onClick(args) { 
            var obj = $("#MainContent_Grid").ejGrid("instance"), rec = []; 
            var check = obj.checkSelectedRowsIndexes;  // collection which holds the page index and the selected record index 
... 
                    if (!ej.isNullOrUndefined(check[pageInx])) 
                        rec = getRecords(pageInx, check[pageInx], obj, rec); 
                } 
            } 
            console.log(rec); 
        } 
        var data; 
        function getRecords(pageInx, inx, proxy, rec) { 
            if (inx.length) { 
                 for (var i = 0; i < inx.length; i++) { 
                    var pageSize = proxy.model.pageSettings.pageSize;  //gets the page size of grid 
                    if (proxy.model.filterSettings.filteredColumns.length) { 
                        data = proxy.getFilteredRecords()[pageInx * pageSize + inx[i]]; 
                    
//get the filtered records using getFilteredRecords in grid. 
 } 
                    else 
                       data = proxy.model.dataSource[pageInx * pageSize + inx[i]]; 
                    rec.push(data);     //pushing all the selected Records 
                } 
            } 
            return rec; 
        } 
            </script> 

Please refer the documentation link 

Please let us know if you need further assistance.  

Regards, 
Manisankar Durai. 



EL Eligio January 10, 2018 06:50 PM UTC

That was really a great anwser!

Good job!


VN Vignesh Natarajan Syncfusion Team January 11, 2018 04:09 AM UTC

Hi Eligio, 

Thanks for the update 

We are happy to hear that your query has been resolved by our solution. 

Kindly get back to us if you need further assistance. 

Regards, 
Vignesh Natarajan 


Loader.
Up arrow icon