How to get purticulaer cell value when another cell in same row is clicked

Hi,
My requirement is to get the value of the 2nd cell of a row when I click in the 3rd cell in the same row. How do I do this. Please help.
Thank you.
Kalum


3 Replies

PK Prasanna Kumar Viswanathan Syncfusion Team September 18, 2018 11:03 AM UTC

Hi Kalum, 

Thanks for contacting Syncfusion support. 

Query : “My requirement is to get the value of the 2nd cell of a row when I click in the 3rd cell in the same row” 

In this we suspect that you need above requirement in cellSelected event of ejGrid. To achieve this, we suggest you to use getColumnByIndex method and cellSelected event of ejGrid. 

Refer the below code example. 


@(Html.EJ().Grid<OrdersView>("FlatGrid") 
        .Datasource((IEnumerable<object>)ViewBag.datasource) 
        .AllowPaging() 
        .AllowSelection() 
        .SelectionSettings(ss=> { 
            ss.SelectionMode(mode => mode.AddMode(SelectionMode.Cell)); 
        }) 
        
        .ClientSideEvents(eve => eve.CellSelected("onGridCellSelected")) 
 
         ---- 
 
        .Columns(col => 
        { 
             
            --- 
 
       }) 
 
) 
 
<script type="text/javascript"> 
 
    function onGridCellSelected(args) { 
        var cellIndex = args.cellIndex[0] - 1; 
        var field = this.getColumnByIndex(cellIndex).field; 
        var cellData = args.data[field]; // you can get the second cell data when you click for the third cell data in a row 
    } 
 
</script> 


We have prepared a sample and it can be downloadable from the below location. 


Refer the help documentation. 



If you are using batch editMode in Grid then we suggest you to follow the below code example. 


@(Html.EJ().Grid<OrdersView>("FlatGrid") 
        .Datasource((IEnumerable<object>)ViewBag.datasource) 
        .AllowPaging() 
        
        .EditSettings(edit => { edit.AllowAdding().AllowDeleting().AllowEditing().EditMode(EditMode.Batch); }) 
             
        .ClientSideEvents(eve => eve.CellEdit("onGridCellEditEvent")) 
 
        .Columns(col => 
        { 
 
            --- 
 
        }) 
 
) 
 
<script type="text/javascript"> 
 
    function onGridCellEditEvent(args) { 
        var cellIndex = args.cell.index() - 1; 
        var field = this.getColumnByIndex(cellIndex).field; 
        var cellData = args.rowData[field];  // you can get the second cell data when you click for the third cell data in a row 
    } 
 
</script> 


We have prepared a sample and it can be downloadable from the below location. 


Refer the help documentation. 


If the above suggestion is not satisfied your requirement, then please share the following details 

1. In what scenario do you need to achieve the mentioned requirement? 

2. Share the complete Grid code example. 

3. Essential Studio Version details. 

Regards, 
Prasanna Kumar N.S.V 



KA kalum September 19, 2018 10:44 AM UTC

Hi Prasanna Kumar,
Your solution works fine. Thank you very much for your valuable help.
Regards,
Kalum


PK Prasanna Kumar Viswanathan Syncfusion Team September 19, 2018 11:16 AM UTC

Hi Kalum, 

We are happy to hear that your issue has been solved. 

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

Regards, 
Prasanna Kumar N.S.V 


Loader.
Up arrow icon