How to select row by primary key instead of by index

Hi.
I would like to select a row (using method "selectRows(...)"), but I only know the primary key of this row. Any idea?
Thanks in advance.
Luis Carlos.

1 Reply

SS Seeni Sakthi Kumar Seeni Raj Syncfusion Team September 5, 2018 05:28 AM UTC

Hi Luis,  
 
Thanks for contacting Syncfusion Support.  
 
Based on the primary key value, you can sort out the index of them in the current view data of the Grid. Current viewdata can be retrieved using the getCurentViewData method. Refer to the following code example.  
 
<input type="button" id="btn"> 
<div id="Grid"></div> 
<script type="text/javascript"> 
    $(function () { 
        $("#btn").ejButton({ 
            text: "Select Row", 
            click: function (args) { 
                var gridObject = $("#Grid").ejGrid("instance"); 
                //get current data 
                var data = gridObject.getCurrentViewData(); 
                var rec = data.filter(function (e) { 
                    return e.OrderID == 10249; 
                })[0]; 
                //get index 
                var inx = data.indexOf(rec); 
                //select row 
                gridObject.selectRows(inx); 
            } 
        }) 
        $("#Grid").ejGrid({ 
            dataSource: window.gridData, 
            allowPaging: true, 
            columns: [ 
                    { field: "OrderID", headerText: "Order ID", isPrimaryKey: true }, 
                       . . .  
                         . . . 
                            
            ] 
        }); 
    }); 
</script> 
 
 
We have prepared a sample that can be referred from the following jsPlayground.  
 
 
Regards,  
Seeni Sakthi Kumar S. 


Loader.
Up arrow icon