Skip to content

This example demonstrates how to select all products that are associated with a required category.

License

Notifications You must be signed in to change notification settings

DevExpress-Examples/devextreme-odatacontext-filter-data-by-foreign-key-value

Repository files navigation

ODataContext for DevExtreme - How to filter data by a foreign key value

This example demonstrates how to select all products that are associated with a required category. The Product entity has the Category navigation property. To filter products by the category ID, we need to expand the Category property using the ODataStore.expand option. In this case, we will be able to access a key field of a navigation property. This example operates with the Northwind online OData service. We can determine that Category is a navigation property of the Product one by typing the following URL in our browser "https://services.odata.org/Northwind/Northwind.svc/$metadata".

ODataContext for DevExtreme - How to filter data by a foreign key value

Implementation Details

var db = new DevExpress.data.ODataContext({
        url: "<a href="https://services.odata.org/Northwind/Northwind.svc">http://services.odata.org/Northwind/Northwind.svc</a>",
        errorHandler: function (error) {
            alert(error.message);
        },
        entities: {
             Products: { key: "ProductID" }
        }
});

var viewModel = {
       dataSource: new DevExpress.data.DataSource({
            store: db.Products,
            select: ['ProductID', 'ProductName', 'Category.CategoryID', 'Category.CategoryName'],
            expand: ['Category'],
            filter: ['Category.CategoryID', '=', 5]
       })
};

Files to Review

Documentation

About

This example demonstrates how to select all products that are associated with a required category.

Topics

Resources

License

Stars

Watchers

Forks