Which cell got clicked in a row?

4 posts, 0 answers
  1. Kenb
    Kenb avatar
    15 posts
    Member since:
    Nov 2014

    Posted 03 Dec 2014 Link to this post

    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>
  2. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2310 posts

    Posted 05 Dec 2014 Link to this post

    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.

     
  3. Kenb
    Kenb avatar
    15 posts
    Member since:
    Nov 2014

    Posted 05 Dec 2014 in reply to Dimiter Madjarov Link to this post

    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?
  4. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2310 posts

    Posted 05 Dec 2014 Link to this post

    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.

     
Back to Top