Question

Can I possibly get properties of all columns in a Grid like width, encoding, field title etc. The goal is to override the column setting of the grid and to save it on the database.

I want to override this for example:

  var columns = new[] 
            {
                new GridColumnSettings
                {
                    Member = "ProductName",
                    Width = "200px"
                },
                new GridColumnSettings
                {
                    Member = "UnitPrice",
                    Width = "130px",
                    Format = "{0:c}",
                },
                new GridColumnSettings
                {
                    Member = "UnitsInStock",
                    Width = "130px"
                },
                new GridColumnSettings
                {
                    Member = "LastSupply",
                    Width = "130px",
                    Format = "{0:d}"
                },
                new GridColumnSettings
                {
                    Member = "Discontinued"
                },
                new GridCommandColumnSettings
                {
                    Commands = 
                    {
                        new GridEditActionCommand(),
                        new GridDestroyActionCommand()
                    },
                    Width = "200px",
                    Title = "Commands"
                }
            };
Was it helpful?

Solution

I would say that the question is not if you can, the question is if you should. The answer is no, you should not.

This is something not supported. A grid is a grid and has it own columns, the columns can be hidden or displayed, can be moved, resized... but the columns should not be dynamically created. As far as you change the width might be ok, but as soon as you try to change the name it is not because that's actually removing a column and creating another.

So, why do you want to do it? Maybe there is a simpler way of getting the same result.

EDIT: If you want to get current column status, you can get them from grid.columns array. Where grid is the the KendoUI Grid object.

Example:

var grid = $("#grid").data("kendoGrid")
console.log("Columns", JSON.stringify(grid.columns));

See it in action here: http://jsfiddle.net/OnaBai/emD5t/2/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top