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

Problem with a nested property when deleting a row

1 Answer 14 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Josef
Top achievements
Rank 1
Josef asked on 09 Mar 2021, 05:09 PM

Hi,

 

I have a grid with nested property 'OrderName'. Not all rows have the OrderName but this is no problem.  Everything works perfect till I want to delete row and this row does not have the OrderName (there is no reference to a Order table/object).

I get the error:

Cannot set property 'OrderId' of null

    at Object.eval [as Order.OrderId] (eval at setter (kendo.all.js:2138), <anonymous>:3:16)

Schema definition:

<schema>
<model id="Id">
<fields>
                            <field name="CreateDate" type="date"></field>
                       
                            <field name="UserName" from="CustomerUser.Name"></field>
                            <field name="AnswerDate" type="date"></field>
                       
                            <field name="OrderName" from="Order.OrderId" default-value="String.Empty"></field>

<field name="Direction" type="number"></field>
<field name="CustomerName" from="Customer.Name" default-value="String.Empty"></field>
</fields>
</model>
</schema>

 

Column definition:

<column field="OrderName" width="150" title="@SharedLocalizer["grid_column_order"].Value" template="@($"# if(OrderId !== null) {{#  <a class='underline' href='{Url.Action("Detail", "Orders")}/#= OrderId #'>#= OrderName #</a>#}}#")"></column>

 

Delete function:

grid.dataSource.remove(dataItem); 
grid.dataSource.sync();

 

1 Answer, 1 is accepted

Sort by
0
Georgi Denchev
Telerik team
answered on 12 Mar 2021, 12:34 PM

Hello Josef,

Thank you for the provided code snippet.

You could check if the Order is null before calling the remove method and if it is assign a dummy object to it.

        if (!dataItem.Order) {
            dataItem.Order = { OrderId: 1 }
        }

        grid.dataSource.remove(dataItem);
        grid.dataSource.sync();

 

Best Regards,
Georgi Denchev
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
Grid
Asked by
Josef
Top achievements
Rank 1
Answers by
Georgi Denchev
Telerik team
Share this question
or