What is the best way to update Kendo grid data whenever I sort a column or click on it?

Below is a grid where the user can click on the subcategory Name column to populate another grid on the right side with data for the selected row. I would like to implement a function for the subcategory Name column so that when the user clicks on it, the data in the right-side grid is refreshed to its default state (no data displayed until a row is selected).

angular.module('thirdPartyManagementApp').value('subCategoryGridConfig', {
subCategoryGrid: {
    sortable: true,
    filterable: true,
    selectable: true,
    height: 600,
    toolbar: [
        {
            template: kendo.template('<kendo-tabstrip><ul><li ng-class="{\'k-state-hover k-state-active\': defaultAllTab}"><a  href="" class="k-grid-add border"  ng-click="getAllSubCategories()">All</a></li>')
        },
        {
            template: kendo.template('<li ng-class="{\'k-state-hover k-state-active\': defaultPendingTab}"><a  href="" class="k-grid-add border" ng-click="getPendingSubCategories()">Pending Review</a></li>')
        },
        {
            template: kendo.template('<li ng-class="{\'k-state-hover k-state-active\': defaultReviewTab}"><a  href="" class="k-grid-add border" ng-click="getReviewedSubCategories()">Reviewed</a></li></ul><kendo-tabstrip>')
        }
    ],
    columns: [
        {
            template: '<strong><span ng-if="this.dataItem.sortCode === 1" class="text-success">NEW</span><span ng-if="this.dataItem.sortCode === 2" class="text-danger">!</span></strong>',
            width: '30px'
        },
        {                           
            template: kendo.template('{{this.dataItem.subCategoryName}}<br/><a  href="" class="linkColor hoverFontColor" ng-click="showDetail(this.dataItem)">Vendors...</a>'),
            field: 'subCategoryName',
            title: 'Subcategory',
            width: '100px',
            refreshFunction: "function(e) {
              subCategoryGrid.columns.filter(function(data) {
                return data.field === 'subCategoryName';
              })
              subCategoryGrid.refresh();
            }"
        },
        {
            field: 'status',
            title: 'Status',
            width: '65px'
        }
    ]
},

Answer №1

If you're using Kendo grid and need sorting functionality, keep in mind that it doesn't have a specific sorting event. However, the datasource includes a change event that is triggered when the data is modified and sorted:

http://docs.telerik.com/kendo-ui/api/javascript/data/datasource#events-change

You can try updating the data within this event handler. Just make sure to check for e.action to avoid getting stuck in a loop.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Encountering a CORS header issue while working with the Authorization header

Here is the code snippet I am currently working with: https://i.stack.imgur.com/DYnny.png Removing the Authorization header from the headers results in a successful request and response. However, including the Authorization header leads to an error. http ...

How to interact with AngularJS drop-down menus using Selenium in Python?

I have been working on scraping a website to create an account. Here is the specific URL: Upon visiting the site, you need to click on "Dont have an account yet?" and then click "Agree" on the following page. Subsequently, there are security questions th ...