We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Search also foreign key value in grid

Thread ID:

Created:

Updated:

Platform:

Replies:

148861 Nov 6,2019 02:31 PM UTC Nov 12,2019 02:37 AM UTC ASP.NET Core 5
loading
Tags: Grid
Marvin
Asked On November 6, 2019 02:31 PM UTC

I have a grid with 5 columns. One column is displayed via foreign key. In grid serach box I can only search the "normal" column values. 
Let say I have in foreign column follow database value:
TypeId = 100
Name = Oring

If I try to search "Oring" the grid show me not found. If I search "100" I get O-Ring.

My code is: 


var dataManager = ej.DataManager({
                url: "/api/Product",
                adaptor: new ej.WebApiAdaptor(),
                offline: true
            });

            dataManager.ready.done(function (e) {
                $("#Grid").ejGrid({
                    dataSource: ej.DataManager({
                        json: e.result,
                        adaptor: new ej.remoteSaveAdaptor(),
                        insertUrl: "/api/Product/Insert",
                        updateUrl: "/api/Product/Update",
                        removeUrl: "/api/Product/Remove",
                    }),
                    toolbarSettings: {
                        showToolbar: true,
                        toolbarItems: ["add", "edit", "printGrid", "search"]
                    },
                    editSettings: {
                        allowEditing: true,
                        allowAdding: true,
                        allowDeleting: false,
                        showDeleteConfirmDialog: true,
                        editMode: "dialogtemplate",
                        dialogEditorTemplateID: "#templateForm",
                    },
                    isResponsive: true,
                    enableResponsiveRow: true,
                    allowSorting: true,
                    allowSearching: true,
                    allowFiltering: true,
                    filterSettings: {
                        filterType: "excel",
                        maxFilterChoices: 100,
                        enableCaseSensitivity: false
                    },
                    allowPaging: true,
                    pageSettings: { pageSize: 10, printMode: ej.Grid.PrintMode.CurrentPage },

                    columns: [
                        { field: "ProductId", type: 'number', headerText: 'OD-No.', defaultValue: 0, isPrimaryKey: true, isIdentity: true, visible: false },
                        { field: "Barcode", type: 'string', headerText: 'P/N', validationRules: { required: true } },
                        { field: "ISO", type: 'string', headerText: 'ISO', validationRules: { required: true } },
                        { field: "TypeList", headerText: 'Type', foreignKeyField: "TypeId", foreignKeyValue: "Name", dataSource: dataManagerType, validationRules: { required: true } },
                        { field: "SupplierPN", type: 'string', headerText: 'SupplierPN', visible: false },                      
                    ],
                    actionComplete: "complete",
                });


            });


        });


Padmavathy Kamalanathan [Syncfusion]
Replied On November 7, 2019 01:08 PM UTC

Hi Marvin,

Thanks for contacting Syncfusion Forums.

QUERY: Search foreign key value in grid

From your query we understand that you are unable to search the foreign key value using Grid's search. For performing searching functionality of the foreign key column, you need to extend the adaptor in the grid's load event.

Please check the below help documentation,


In the above documentation, we have extended the JSON adaptor to ForeignKey Adaptor. Similarly, you can extend your adaptor to ForeignKey Adaptor in order to achieve your requirement.

If you have further queries, please get back to us.

Regards,
Padmavathy Kamalanathan


Marvin
Replied On November 7, 2019 04:13 PM UTC

Thanks for fast reply.

It dosen't work. The grid shows only a loading symbol.

My code:

//In grid
load:  function(args) {
                        this.model.dataSource.adaptor = new ej.ForeignKeyAdaptor([{ field: "TypeList", foreignKeyField: "TypeId", foreignKeyValue: "Name", dataSource: dataManagerType }], "WebApiAdaptor");

                    },


 dataManagerType = ej.DataManager({
                url: "/api/ProductType1",
                adaptor: new ej.WebApiAdaptor()
            });

Padmavathy Kamalanathan [Syncfusion]
Replied On November 8, 2019 12:41 PM UTC

Hi Marvin,

Thanks for your update.

From your code, we can understand that you have extended the WebApi Adaptor and not the RemoteSave Adaptor which you have used for performing CRUD operations in Grid. We suggest you to extend the RemoteSaveAdaptor.

Still facing the issue, please get back to us.

Regards,
Padmavathy Kamalanathan


Marvin
Replied On November 8, 2019 04:10 PM UTC

I try it. I dosen't work.

Code:

dataManager.ready.done(function (e) {
                $("#Grid").ejGrid({
                    dataSource: ej.DataManager({
                        json: e.result,
                        adaptor: new ej.remoteSaveAdaptor(),
                        insertUrl: "/api/Product/Insert",
                        updateUrl: "/api/Product/Update",
                        removeUrl: "/api/Product/Remove",
                    }),
                    toolbarSettings: {
                        showToolbar: true,
                        toolbarItems: ["add", "edit", "printGrid", "search"]
                    },
                    editSettings: {
                        allowEditing: true,
                        allowAdding: true,
                        allowDeleting: false,
                        showDeleteConfirmDialog: true,
                        editMode: "dialogtemplate",
                        dialogEditorTemplateID: "#templateForm",
                    },
                    isResponsive: true,
                    enableResponsiveRow: true,
                    allowSorting: true,
                    allowSearching: true,
                    allowFiltering: true,
                    filterSettings: {
                        filterType: "excel",
                        maxFilterChoices: 100,
                        enableCaseSensitivity: false                
                    },
                    allowPaging: true,
                    pageSettings: { pageSize: 100, printMode: ej.Grid.PrintMode.CurrentPage },
                   

                    columns: [
                        { field: "ProductId", type: 'number', headerText: 'OD-No.', defaultValue: 0, isPrimaryKey: true, isIdentity: true, visible: false },
                        { field: "Barcode", type: 'string', headerText: 'P/N', validationRules: { required: true } },
                        { field: "ISO", type: 'string', headerText: 'ISO', validationRules: { required: true } },
                        { field: "TypeList", headerText: 'Type1', foreignKeyField: "TypeId", foreignKeyValue: "Name", dataSource: dataManagerType, validationRules: { required: true } },
                        { field: "SupplierPN", type: 'string', headerText: 'SupplierPN', visible: false },
                        { headerText: "Type2", template: "<span>{{:TypeList}}</span > " },
                      
                    ],
                    actionComplete: "complete",
                    load: "gridLoad",
                });


            });


        });

        function gridLoad(args) {

            this.model.dataSource.adaptor = new ej.ForeignKeyAdaptor([{ field: "TypeList", foreignKeyField: "TypeId", foreignKeyValue: "Name", dataSource: dataManagerType }], "remoteSaveAdaptor");
        }


Padmavathy Kamalanathan [Syncfusion]
Replied On November 12, 2019 02:37 AM UTC

Hi Marvin,

Thanks for your update.

We have created sample for your convenience. In the sample, we have binded JSON Data to ForeignKey Column and extended it as ForeignKey Adaptor. Please check whether you are binding data to foreign key column from json/remote save adptor and extend that to foreign key adaptor.

Please check the below sample,

If you have further queries, please get back to us.

Regards,
Padmavathy Kamalanathan


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon