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

Unable to get value of cell when calling JS function

1 Answer 96 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Laurie
Top achievements
Rank 1
Laurie asked on 17 Feb 2017, 06:18 PM

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.

1 Answer, 1 is accepted

Sort by
0
Viktor Tachev
Telerik team
answered on 20 Feb 2017, 01:36 PM
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.
Tags
Grid
Asked by
Laurie
Top achievements
Rank 1
Answers by
Viktor Tachev
Telerik team
Share this question
or