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

Null error on Update Function

1 Answer 108 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Allan
Top achievements
Rank 1
Allan asked on 31 May 2016, 08:51 AM

Hi,

I have written a function that triggers when the Update event on the grid ends.  This is defined as :

.DataSource(dataSource => dataSource
               .Ajax()
               .Events(events =>
                   {
                       events.RequestEnd("onUpdateEnd");
                   })
               .Model(model =>
               {
                   model.Id(p => p.vessel_idx);                   
               })

My function is as follows:

function onUpdateEnd(e) {
 
       if (e.type == "update") {
           var grid = $("#Grid").data("kendoGrid"),
               dataItem = grid.dataItem($(this).closest("tr")),
               stop_date = document.getElementById("fixture_stop"),
               start_date = dataItem.fixture_start;
            
           if (end_date < start_date) {
               alert("Dates are wrong")
           } else {
               alert("Dates are correct")
           }
           $("#Grid").data("kendoGrid").dataSource.read();
       }      
   }

The problen that once the updateend function trigger, the console returns an error saying that dataItem is null (start_date) which crashes the application.  What am I doing wrong and why can't I grab that cell data for use in my function?

Many thanks

 

1 Answer, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 02 Jun 2016, 06:33 AM
Hello Allan,

Thank you for contacting us.

Could you please elaborate what you are trying to achieve, so we can suggest you the best approach for it? In the provided code snippet, the issue that you are facing is due to the fact that "this" will be the DataSource object and no TR element will be found with .closest("tr"). If you need to get reference to the record from the DataSOurce you could use the event arguments:
e.response.Data[0].fixture_start

If any further assistance is needed, please provide additional information on the exact requirement that you have.

I am looking forward to your reply.


Regards,
Konstantin Dikov
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Allan
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Share this question
or