We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

I want to get the field value by selecting the cells in the grid

Thread ID:

Created:

Updated:

Platform:

Replies:

141785 Jan 4,2019 06:00 AM UTC Jan 9,2019 09:37 AM UTC ASP.NET Core - EJ 2 5
loading
Tags: DataGrid
bright
Asked On January 4, 2019 06:00 AM UTC

in EJ2, I want to get the field value by selecting the cells in the grid, I am using the QueryCellInfo event now. Below is my code.






Pavithra Subramaniyam [Syncfusion]
Replied On January 4, 2019 07:14 AM UTC

Hi bright, 
 
Thanks for contacting Syncfusion support. 
 
You can achieve your requirement by using the “cellSelected” or “cellSelecting” event of Grid component. Please refer to the below code example and documentation link for more information. 
 
[index.cshtml] 
<ejs-grid id="GridUS_doc" enableHover="false" allowPaging="true" allowResizing="true" allowSorting="true" allowSelection="true" allowGrouping="true" cellSelected="cellSelected" dataSource="ViewBag.dataSource" > 
    <e-grid-groupsettings columns="@(new string[] { "EmployeeID"})" showGroupedColumn="false" showDropArea="false"></e-grid-groupsettings> 
    <e-grid-pageSettings pageCount="2" pageSize="5"> </e-grid-pageSettings> 
    <e-grid-selectionSettings mode="Cell" type="Single"></e-grid-selectionSettings> 
    <e-grid-columns> 
        <e-grid-column field="OrderID" headerText="ID" isPrimaryKey="true" textAlign="Right"></e-grid-column> 
        <e-grid-column field="CustomerID" headerText="CustomerID" isPrimaryKey="true" textAlign="Left"></e-grid-column> 
        <e-grid-column field="EmployeeID" headerText="EmployeeID" textAlign="Left"></e-grid-column> 
        <e-grid-column field="Freight" headerText="Freight" textAlign="Left"></e-grid-column> 
        <e-grid-column field="ShipName" headerText="ShipName" width="150"></e-grid-column> 
    </e-grid-columns> 
</ejs-grid> 
<script> 
    function cellSelected(e) { 
        var grid = document.getElementsByClassName('e-grid')[0].ej2_instances[0]; 
        var field = grid.columns[e.cellIndex.cellIndex].field; 
        console.log("field-- "+ field); 
    } 
</script> 
 
 
Regards, 
Pavithra S. 


bright
Replied On January 4, 2019 08:57 AM UTC

Thank you very much for your answer. Another question is how to set a right click to select a cell.

Regards,
 
Bright

Pavithra Subramaniyam [Syncfusion]
Replied On January 7, 2019 08:54 AM UTC

Hi bright, 
 
You can achieve your requirement by binding the JavaScript “mousedown” or “contextmenu” event to the Grid element. In that event you can select the Grid cells by using the “selectCell” method. Please refer to the below code example, Documentation link and sample link. 
 
[inde.cshtml] 
<ejs-grid id="GridUS_doc" created='created' allowPaging="true"cellSelected="cellSelected" dataSource="ViewBag.dataSource"> 
    <e-grid-selectionSettings mode="Cell" type="Single"></e-grid-selectionSettings> 
    <e-grid-columns> 
        <e-grid-column field="ShipName" headerText="ShipName" width="150"></e-grid-column> 
        .  .  . 
    </e-grid-columns> 
</ejs-grid> 
<br /> 
<script> 
    function created(args) {  
        // we are binding the mousedown event inside the “created” event of Grid. 
        this.element.addEventListener("mousedown", function (e) { 
            if (e.button == 2 && e.target.classList.contains("e-rowcell")) { 
                var grid = document.getElementsByClassName('e-grid')[0].ej2_instances[0] 
                var rowObj = grid.getRowObjectFromUID(ej.base.closest(e.target, '.e-row').getAttribute('data-uid'));  // getting row information 
                var r_index = rowObj.index; 
                var c_index = parseInt(e.target.getAttribute("aria-colindex")); 
                grid.selectCell({ rowIndex: r_index, c_index: }, true); 
            } 
        }); 
    } 
    </script>  
 
 
                              https://ej2.syncfusion.com/documentation/api/grid#selectcell  
 
 
Please refer the sample for further details, 
 
Regards, 
Pavithra S. 


bright
Replied On January 9, 2019 06:02 AM UTC

Perfect, this solved my problem,thanks。

Pavithra Subramaniyam [Syncfusion]
Replied On January 9, 2019 09:37 AM UTC

Hi bright, 

Thanks for your update.  

We are happy to hear that your issue has been resolved now. 

Please contact us if you need further assistance. 

Regards, 
Pavithra S. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;