Unable to get value of cell when calling JS function

2 posts, 0 answers
  1. Laurie
    Laurie avatar
    5 posts
    Member since:
    Sep 2012

    Posted 17 Feb 2017 Link to this post

    Currently I'm trying to access the value of a cell in the grid, but the property is always undefined.

                                 @(Html.Kendo().Grid<IA.Models.PatientInfo>()
                                  .Name("PatientGrid")
                                  .Columns(columns =>
                                  {
                                      columns.Bound(c => c.PatientId).Title("Id").Width(50);
                                      columns.Bound(c => c.FullName).Width(200);
                                      columns.Bound(c => c.DOB).Width(140).Title("Date of Birth").Format("{0:dd/MM/yyyy}");
                                      columns.Bound(c => c.MANumber).Width(90);
                                      //columns.Command(command => { command.Destroy(); }).Width(50);
                                      columns.Command(c => c.Custom("Delete").Click("open")).Width(50);
                                  })
                                  .Filterable()
                                  .Sortable()
                                  .Selectable()
                                  .Pageable(pageable => pageable
                                  .PageSizes(true)
                                  .ButtonCount(5))
                                  //.HtmlAttributes(new { style = "height: 80px" })
                                  .Events(ev => ev.DataBound("function(){this.trigger('change')}"))
                                  .DataSource(dataSource => dataSource
                                    .Ajax()
                                    .Destroy(update => update.Action("Destroy", "Provider"))
                                    .Read(read => read.Action("Patient_Read", "Provider", new { id = Model.ProviderId }))
                                    .PageSize(10)
                                    .ServerOperation(false)
                                    .Model(model =>
                                    {
                                        model.Id(m => m.PatientId);
                                    })
                                    )

             )

            <script type="text/javascript">

                function open(e) {
                    e.preventDefault();

                    var row = $(e.currentTarget).closest("tr");

                       var test = row.PatientId;
                        alert(test);
                       }

    </script>

     

    I've also I've also tried using selectItem() and that doesn't seem to work either.

  2. Viktor Tachev
    Admin
    Viktor Tachev avatar
    2495 posts

    Posted 20 Feb 2017 Link to this post

    Hello Laurie,

    I have replied to your query in the support ticket you have submitted. With that said, please avoid submitting duplicate threads. This will enable us to keep better track of your support history and provide better answers quicker.

    As reference I will paste the answer below in case anyone is having similar issue.

    ----------------

    In order to get the value for a specific field you need to get reference of the dataItem first. For that you can use the dataItem method. Then you can access the values in the item. Please examine the demo below that illustrates the approach.


    I have also prepared a small example for reference.




    Regards,
    Viktor Tachev
    Telerik by Progress
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top