This is a migrated thread and some comments may be shown as answers.

Which cell got clicked in a row?

3 Answers 82 Views
Grid
This is a migrated thread and some comments may be shown as answers.
IPV
Top achievements
Rank 1
IPV asked on 04 Dec 2014, 05:39 AM
I have a grid and event like this.  The text placed in a label in the last line of the script depends upon which of two columns got clicked; HomeAddress or BizAddress.  .If the user clicked the Name column instead of one of the two address columns, I want to do nothing.

How can I tell that so I can pick which field to put in the label text?

@(Html.Kendo().Grid<AppUser>()
      .Name("grid")
      .Columns(columns =>
      {
          columns.Bound(c => c.Name).Width(140);
          columns.Bound(c => c.HomeAddress).Width(140);
          columns.Bound(c => c.BizAddress).Width(140);
      })
      .HtmlAttributes(new { style = "height: 380px;" })
      .Scrollable()
      .Groupable()
      .Sortable()
      .Selectable()
      .Events(events => events.Change("grid_change"))
      .Pageable(pageable => pageable
          .Refresh(true)
          .PageSizes(true)
          .ButtonCount(5))
      .DataSource(dataSource => dataSource
          .Ajax()
          .Read(read => read.Action("FilteredPeople_Read", "UserConsoleViewModels"))
      )
)
<script>
    function grid_change(e) {
        var data = this.dataItem(this.select());
        if (clickedColumnIndex != 0)  // How do I find selectedColumnIndex?
        {
            $("#labelName").text(data.Name);       
            $("#labelAddress").text(selectedColumnIndex == 1 ? data.HomeAddress : data.BizAddress); 
        }
    }
</script>

3 Answers, 1 is accepted

Sort by
0
Dimiter Madjarov
Telerik team
answered on 05 Dec 2014, 12:48 PM
Hello Morgan,


If a row selection mode is used, accessing the clicked cell in the change event is not supported. You could try using the cell selection mode instead.

Regards,
Dimiter Madjarov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
IPV
Top achievements
Rank 1
answered on 05 Dec 2014, 03:55 PM
Ok... that could work... given this:

.Events(events => events.Change("grid_change"))
 
and this

function grid_change(e) {
     var rowDataItem = ????
     var columnIndex = ????

How do I find out the column index of that clicked cell and get the row item I used to get when using GridSelectionType.Row?
0
Dimiter Madjarov
Telerik team
answered on 05 Dec 2014, 04:20 PM
Hello Morgan,


Are you referring to the cell selection mode, which I mentioned in my previous post? If that is the case here is a runnable example, which demonstrates how to access the index, the row and it's dataItem.

Regards,
Dimiter Madjarov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
IPV
Top achievements
Rank 1
Answers by
Dimiter Madjarov
Telerik team
IPV
Top achievements
Rank 1
Share this question
or