Shashi
Shashi

Reputation: 1182

Kendo grid Column align based on column data

I wanted to set column align properties across all grids in my application based on the data.

Is there a way where I could align the columns to center if they are of type decimal/number and otherwise align left for all other types.

I do not have column schema's I will need to determine it before the data is being rendered.

Upvotes: 1

Views: 3310

Answers (2)

Polynomial Proton
Polynomial Proton

Reputation: 5135

You can use the template field to determine the datatype and set a template for the column.

  $("#grid").kendoGrid({
  columns: [
    { 
    title: "FieldName", 
    field: "Name", 
    template: '#=Getvalue(Name)#' 
    }
     ],
....
});


 function Getvalue(value) {

            if (//check datatype)
                return "<span style='text-align: right'>"+ value+"</span>";
                //or add a custom class
            else
                return value;
        }

Upvotes: 0

Dalorzo
Dalorzo

Reputation: 20014

How about using attributes like :

$("#grid").kendoGrid({
  columns: [ {
    field: "someField",
    title: "Some Name",
    attributes: {
      "class": "table-cell",
      style: "text-align: center"
    }

Upvotes: 2

Related Questions