Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

KendoUI Grid - how to add a class to the generated table

I'm generating a KendoUI Grid using ajax dataSource. The table is generated and by default has no class. To keep it looking uniform with the rest of the site, I'd like to add a class "interactive" to it.

$("#pending_documents").kendoGrid({
    dataSource: {
        transport: {
            read: "/get-data?type=1"
        },
        schema: {
            data: "data",
            total: "total"
        },
        pageSize: 2,
        serverPaging: true,
        serverFiltering: true,
        serverSorting: true,
        reorderable: true
    },
    height: 500,
    filterable: {
        extra: false
/*
, ui: "datetimepicker" // use Kendo UI DateTimePicker
*/
    },
    sortable: true,
    pageable: {
        pageSize: 2        },
    columns: [...]
});
    });

I know that I can do this using JQuery.addClass() method, run after the grid is generated, however if there a way of setting it in the grid setup/configuration?

Thanks in advance.

like image 777
Katya S Avatar asked May 29 '13 11:05

Katya S


People also ask

How do I add a style to Kendo grid?

You can add a custom CSS class or style to a column header by using the following ColumnComponent options: headerClass —Specifies the class to be added to the header cell.

How do I set data for Kendo grid?

Bind data to Kendo Grid by using AJAX Read action method. Change the datasource on change event of any HTML controls. Normally, a developer can bind the data to Grid by using AJAX Read method. This read method is ActionResult method in MVC which will return JSON DataSourceResult & direclty bind the data to Grid.

What is Databound event in kendo grid?

Fired when the widget is bound to data from its data source. The event handler function context (available via the this keyword) will be set to the widget instance.


1 Answers

I guess you don't have any other choice but to use addClass(). Can't find anything on their documentation about setting a grid's(not grid column) htmlAttributes using built-it property in JS. I tried it also with no success. Unless you declare it like this (C#):

@(Html.Kendo().TabStrip()
    .Name("TabStrip")
    .HtmlAttributes( new { @class = "newclass"})
)

But if you really need it in JS, then you'll have to do it like this:

$("#pending_documents").kendoGrid({
dataSource: {
   //code
  }
}).addClass("newclass");
like image 82
Jude Duran Avatar answered Oct 23 '22 08:10

Jude Duran