How to use value from another field as data for a ForeignKey dataSource

1 Answer 123 Views
Grid
Rob
Top achievements
Rank 2
Iron
Veteran
Iron
Rob asked on 23 Sep 2022, 02:48 AM | edited on 26 Sep 2022, 09:45 PM
I've been trying to solve this with functions and the like, but don't seem to be able to find an answer.

Is there anyway I can pass the type field value in the datasource for the foreign key column?
This will allow me to populate the tenantId list based on the type of Row.


toolbar: ["create"], columns: [ { field: "id", title: "Id", hidden: true }, { field: "type", title: "type", hidden: true }, { field: "tenantId", filterable: { multi: true, search: true} ,width: "200px", dataTextField: "name", dataValueField: "id", dataSource: { type: "json", transport: { read: { url: '@Url.Action("GetSyncingTennantsJsn", "dB")', data: { type: ##I want to pass 'type' value for this row## } } } } }, { field: "folder", title: "Folder" },


Many thanks!

Rob

1 Answer, 1 is accepted

Sort by
0
Accepted
Rob
Top achievements
Rank 2
Iron
Veteran
Iron
answered on 26 Sep 2022, 09:42 PM | edited on 26 Sep 2022, 09:46 PM

I solved it , a long approach , which I was hoping not to have to do , but here it is for anyone else looking for a similar solution

Because I can only get the 'type' value in the edit event , I pass a default value of -1 for when the Grid is drawn. I just had to change the controller to recognise -1 as a type and respond with all values.

            { field: "type", title: "type", hidden: true },
            {
                field: "tenantId", filterable: { multi: true, search: true }, width: "200px",
                dataTextField: "name",
                dataValueField: "id",
                dataSource: {
                    transport: {
                        read: {
                                    url: '@Url.Action("GetSyncingTennantsJsn", "dB")',
                                    data: { type: -1 }
                                }
                    }
                },
                editor: function(container, options) {
                    var input = $("<input/>");
                    input.attr("name", options.field);
                    input.appendTo(container);
                    input.kendoDropDownList({
                        dataTextField: "name",
                        dataValueField: "id",
                        dataSource: {
                            transport: {
                                read: {
                                    url: '@Url.Action("GetSyncingTennantsJsn", "dB")',
                                    data: { type: options.model.type }
                                }
                            }
                        }
                    })}},
            { field: "folder", title: "Folder" },

Regards

Rob

Nikolay
Telerik team
commented on 27 Sep 2022, 02:15 PM

Hi Rob,

Thank you for sharing the solution with the community. I believe it will be helpful to others facing the same scenario.

Regards,

Nikolay

Tags
Grid
Asked by
Rob
Top achievements
Rank 2
Iron
Veteran
Iron
Answers by
Rob
Top achievements
Rank 2
Iron
Veteran
Iron
Share this question
or