简体   繁体   中英

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.

How about using attributes like :

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

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;
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM