iterate through grid rows

hello,

i am using synfusion gridview with column including text field and wanted to know if there a method to loop through rows and get column values.


Thank you,

Best Regards,


5 Replies 1 reply marked as answer

MA Mohammed Ansar Sathik Ali Syncfusion Team April 18, 2022 12:32 PM UTC

Hi Jack,


Thanks for contacting Syncfusion support.


Query: Iterate through grid rows


Based on your query, you need to iterate through the rows and get the column values. We can achieve this by using getRows method to get the all the rows and get the required row’s details using getRowInfo method to get the information of the Respective row. Now you are able to get the column values


For your convenience, we have attached documentation for your reference.


Documentation:

                                https://ej2.syncfusion.com/javascript/documentation/api/grid/#getrows

                                https://ej2.syncfusion.com/javascript/documentation/api/grid/#getrowinfo


Please get back to us if you need further assistance on this.


Regards,

Mohammed Ansar ,



JA jack April 19, 2022 07:54 AM UTC

hello,

thank you for your reply and for the information provided.

I have tried multipe scripts but i am not able to loop and get always object or empty result i am using below sample :

  var gridObj = document.getElementById('Listgrid').ej2_instances[0] //Grid Instance

        var getRows = gridObj.getRows(); //get the grid rows by invoking getRows() method

        for (var i = 0; i < getRows.length  ; i++) {

            var val = gridObj.getRowInfo(gridObj.getRows()[i]) ;

       }


appreciate if i can have a small working similar sample.

thank you for your help,

Regards,




MA Mohammed Ansar Sathik Ali Syncfusion Team April 20, 2022 01:45 PM UTC

Hi Jack,


Greetings from Syncfusion support.


Query: To get the column value through iteration


Based on your query, you need to get the column values through iteration. You send us your code example. we suspect that you get the column elements through iteration. For values you need get rowData from getRowInfo method and access your corresponding field name to get the value of corresponding column.


we modified the provided code for more information.


 var gridObj = document.getElementById('Listgrid').ej2_instances[0] //Grid Instance

        var getRows = gridObj.getRows(); //get the grid rows by invoking getRows() method

        for (var i = 0; i < getRows.length  ; i++) {

            var val = gridObj.getRowInfo(gridObj.getRows()[i]) ;

       }

      val.rowData.OrderID// OrderID is my field name



Please get back to us, if you need further information.


Regards,

Mohammed Ansar ,


Marked as answer

JA jack April 22, 2022 07:37 AM UTC

hello Mohammad,

Thank you for your answer , it is working perfectly now and returned values


appreciate your help,

best Regards,



MA Mohammed Ansar Sathik Ali Syncfusion Team April 25, 2022 06:39 AM UTC

Hi Jack,


Thanks for your update.


We are happy to hear that issue has been resolved.


Please get back to us if you need further assistance on this.


Regards,

Mohammed Ansar ,


Loader.
Up arrow icon