What are some ways to personalize column design when a Kendo grid column is automatically created?

I am populating the Kendo grid with data using JavaScript:

var dataSource = new kendo.data.DataSource({
    transport: {
        read: {
            url: "@Url.Action("GetProductList", "Home")",
            type: "POST"
        }
    }       
});
var grid = $("#gridHardwares").kendoGrid({
    dataSource: dataSource,
    height: 600,
    sortable: true,
    groupable: true,
    pageable: {
        refresh: true,
        pageSizes: true,
        buttonCount: 5
    },
    resizable: true
}).data("kendoGrid");

The datasource column expands dynamically every year.

Given this dynamic nature, customizing columns with additional checkbox column, header edits, and groupFooterTemplate is challenging. What approach can be taken to achieve these customizations?

In the past, fixed columns allowed for easy customization like so:

columns: [
{
    template: "<input type='checkbox' class='checkbox' />",
    width: 20
}, {
    field: "PRODUCT_NAME",
    title: "Product Name",
    width: 200
}, {
    field: "PRICE2017",
    title: "Price 2017",
    width: 200,
    aggregates: ["sum", "average"],
    groupFooterTemplate: "Sum: #= kendo.toString(sum, '0.00') # || Average: #= kendo.toString(average, '0.00') #"
}]

Furthermore, explorations on making grid data editable are sought after. How can the grid's data be edited?

Answer №1

Sharing my solution here in case it can aid someone down the road.

    var customColumns =  [{
            template: "<input type='checkbox' class='checkbox' />",
            width: 20
        }];

Next, create your own customized title: var customHeaders = []

    for (var i = 0; i < customHeaders.length; i++) {
    if (i > 4) // proceeding after Name, Description, Region etc..
    {
        if (i == 5) // beginning with the first price column
        {
            customColumns.push({ 
                title : customHeaders[i], 
                field: headers[i],
                width: 150,
                template:
                    "# if(" + headers[i] + " != null) {# " +
                    "#= kendo.toString(" + headers[i] + ", 'n') #" +
                    "# } else { #" +
                    "" +
                    "#} # ",
                aggregates: ["sum", "average"],
                groupFooterTemplate: "Sum: #= kendo.toString(sum, '0.00') # || Average: #= kendo.toString(average, '0.00') #"
            });
        }
        else // comparing price with previous year
        {
            customColumns.push({ 
                title : customHeaders[i], 
                field: headers[i],
                width: 150,
                template:
                    "# if(" + headers[i] + " != null) {# " +
                    "#= calculatePercentage(" + headers[i-1] + ", " + headers[i] + ") #" +
                    "# } else { #" +
                    "" +
                    "#} # ",
                aggregates: ["sum", "average"],
                groupFooterTemplate: "Sum: #= kendo.toString(sum, '0.00') # || Average: #= kendo.toString(average, '0.00') #"
            });
        }
    }
    else
    {
        customColumns.push({ 
            title : customHeaders[i], // personalized header
            field: headers[i] // original header
        });
    }
}

Appreciate the insights, Sandman!

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

Displaying the servlet response within an iframe

This is the content of Content.jsp <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> &l ...

Creating multiple JSON files on disk from a JSON array using NodeJS

My goal was to utilize NodeJS for reading a JSON array from a file, and then save each JSON object into multiple separate JSON files on the disk. However, I encountered an error message stating EMFILE: too many open files. The array in question contains ...

Using React Native to integrate a JSON string into a button

I'm currently working on an app to explore the functionality of websockets in react native. I have successfully retrieved data from the websocket in JSON format and can output it to the console using console.log. However, my goal is to display a speci ...

What is the best way to list the choices associated with a specific category?

The Node.js package I'm currently working with requires an argument of a specific type, which I can see is defined through a TypeScript declaration as follows: export declare type ArgType = 'A' | 'B' | 'C'; I am interes ...

Experiencing browser crashes following the incorporation of asynchronous functions into a JavaScript file. Seeking solutions to resolve this

In my recent project, I developed a basic online store application using vanilla javascript and ES6 classes. The shop items are stored in a JSON file which I used to populate the user interface. To implement functions like "addToCart", "quantityChange", a ...

Ngrx/effects will be triggered once all actions have been completed

I've implemented an effect that performs actions by iterating through an array: @Effect() changeId$ = this.actions$.pipe( ofType(ActionTypes.ChangeId), withLatestFrom(this.store.select(fromReducers.getAliasesNames)), switchMap(([action, aliases ...

Chrome is experiencing a delay in closing the Select Option dropdown menu

On my webpage, I have two select option buttons placed on different tabs. Whenever one button is changed, I want to update the value of the other button and assign it to a specific element like a span in the example code provided. While everything works sm ...

Loading the Facebook JavaScript SDK asynchronously using React and Redux

I have a process that involves loading a JavaScript SDK, which looks like this: class Facebook{ constructor(){ window.fbAsyncInit = () => { FB.init({ appId : 'myappID', ...

Having trouble retrieving the data from the second child object in an object returned by an API call in a

Having trouble accessing the second child object of an object generated by an API response. The weather API in question can be found at . Refer to Display.js for a detailed explanation. App.js import React,{useState} from 'react'; import Navbar ...

Is there a way to determine the quantity of lines within a div using a Vue3 watcher?

Is it feasible to determine the number of text lines in a div without line breaks? I am looking to dynamically display or hide my CTA link based on whether the text is less than or equal to the -webkit-line-clamp value: SCRIPT: const isExpanded = ref(true ...

Compiling Directives in AngularJS for Faster Page Loading

I'm currently experiencing performance issues in my Angular application. The root cause seems to be the excessive use of a directive on a single page. Unfortunately, I don't have the time to break down this page into multiple sections. I am seek ...

Discovering the window scroll unit when clicking, as a page smoothly transitions to the top for a specified target position

Is there a way to achieve parallax scrolling on window scroll and navigation click simultaneously? When navigating and animating the page to the top to show the target, I also want to get the window scroll unit. How can I obtain the window scroll unit on ...

I am encountering a problem with IE11 where I am unable to enter any text into my

When using Firefox, I can input text in the fields without any issues in the following code. However, this is not the case when using IE11. <li class="gridster-form" aria-labeledby="Gridster Layout Form" alt="Tile Display Input column Input Row ...

What is the reason for Javascript XMLHttpRequest returning the octet-stream MIME type response as a string instead of binary

My attempt to retrieve a gltf binary file using the XMLHttpRequest method was unsuccessful. Below is the code I used. var xhr = new XMLHttpRequest(); xhr.open("GET","THE ADDRESS",true); xhr.setRequestHeader("Accept", "application/octet-stream"); xhr.respo ...

Moving the starting directory of a NodeJS application on Azure

My NodeJS app on Azure was initially written in Javascript with the app.js file located in the root directory. This file was automatically detected during deployment via Git. Recently, I converted the app to Typescript and now have a build directory, with ...

What could be the reason why the AngularJS form is set to read-only

Explaining the setup of my app in HTML: <div ng-app="md-app"> <div id="general"> <ng-include src="template1" ng-controller="GeneralCtrl"></ng-include> </div> </div> The JavaScript function to fetch a pe ...

Conquering disparities in standards mode with Javascript

Having an issue with this code snippet: function scrollLeft() { document.body.scrollLeft -= scrollSpeed; } While it works fine in Chrome and Safari, it doesn't seem to work in IE and Firefox. Found out that the problem lies in the fact that Fire ...

Error message in React Js indicating the absence of a specified file or directory: "Package.json cannot

When I try to run npm start, I encounter the following error - PS D:\React\operations_app_tut> npm start npm ERR! path D:\React\operations_app_tut\package.json npm ERR! code ENOENT npm ERR! errno -4058 npm ERR! syscall open npm ...

Dynamically change the fill color of an SVG using styled-components

I've been attempting to target the fill property of my SVG using CSS in styled-components without any luck. Here is my SVG: <svg width="65" height="19" viewBox="0 0 65 19" fill="none" xmlns="http://www. ...

Convert the Date FR and Date US formats to ISO date format

There is a function in my code that accepts dates in different formats. It can handle two formats: 2022-06-04 or 04/06/2022 I want all dates to be in the format: 2022-06-04 For instance: public getMaxduration(data: object[]): number { data.forEach((l ...