getSelectedRecords() with dynamic columns for ej-grid

Hello,

I would like to get the value of a column for the selected row without knowing the Field of the said column, but by knowing its index.


My JS code so far :


function rowSelected() {
      
        var GetSelectedID = $("#grid").ejGrid("instance").getSelectedRecords()[0].myColumnFieldByIndex;

        function setMyValue(value) {
            $('#GetID').val(value);
        }
        setMyValue(GetSelectedID)



I have not found a getColumn fonction that would return the string of the column field by knowing its index.

Thanks.

3 Replies

FS Farveen Sulthana Thameeztheen Basha Syncfusion Team October 22, 2018 12:39 PM UTC

Hi Eric, 

Thanks for contacting Syncfusion Support. 

We have checked your reported query and you can get the selected Records value from getColumnByIndex as like given below. 

Please refer to the code example:- 

   <ej-grid id="Grid" allow-paging="true" allow-filtering="true" row-selected="rowSelected"> 
        
        <e-columns> 
            .  . .  . 
       </e-columns> 
    </ej-grid> 
   <script> 
       function rowSelected(args){ 
           var Field = this.getColumnByIndex(2).field; 
           var GetSelectedID = $("#Grid").ejGrid("instance").getSelectedRecords()[0][Field]; 
           alert(GetSelectedID); 
        } 
   </script> 


Please get back to us if you need any further assistance. 

Regards, 

Farveen sulthana T 



ER Erik October 23, 2018 08:19 AM UTC

Thank you Farveen.


VN Vignesh Natarajan Syncfusion Team October 23, 2018 09:18 AM UTC

Hi Eric, 


Thanks for the update.  


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


Please get back to us if you have any further queries. 


Regards, 
Vignesh Natarajan   


Loader.
Up arrow icon