This is a migrated thread and some comments may be shown as answers.

Tweaking the implicit template

0 Answers 103 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Richard
Top achievements
Rank 1
Richard asked on 10 Jun 2012, 01:26 PM
When a grid does not have a rowTemplate specified the kendoGrid configuration the component will build an implicit default template.

I have a situation where the grid is displaying columns A,B,C,D from a data source having A,B,C,D,X,Y,Z and I need to twiddling an entire row when some condition exists amongst X, Y and Z.

The real problem is more involved in this manner and involves a Database view V on the server and XML data responses.
  1. dataSource1 fetches column names from metadata of V
  2. dataSource2 fetches data from V
  3. grid displays some columns of dataSource2 (A,B,C,D) and needs to set css of row based on X,Y,Z
dataSource1.
  • each column name is used to setup the filelds: property of dataSource2 schema:model
    fields[this.name] = this.name+'/text()';
dataSource2.
  • every column in V will be available
grid
  • the actual columns displayed can be controlled by the user by typing in a list of regex's such as
    ^store ^city ^state ^zip mgr
    A routine guess() will take the input and find matching column names (case-insensitve).  This makes using a static template difficult.
The grid setup is thus:
$("#stores").kendoGrid({
    dataSource: dataSource,
    autoBind: false,
    selectable: "multiple",
    groupable: true,
    resizable: true,
    reorderable: true,
    columns: guess('^store ^city ^state ^zip'),
    dataBound: function (e) {
        $(e.sender.wrapper).find('[data-row-is-special=true]').addClass('my-row-is-special');
    }
});

The only piece remaining is how do I set data element 'row-is-special' when I am not using a custom template.  

The solution I chose was to tweak grid in the following manner:
  • Add a new property named "onCloseImplicitRowTag" to the templateSettings: property of the grid configuration
  • and use it my grid configuration:
  • templateSettings: { onCloseImplicitRowTag: '# if (X && X != Z && Y && Y > 0) {# data-row-is-special="true" #}#' }
If everything is functioning properly the grids implicit <TR will get a data-row-is-special=true and databound will convert that info into a class setting that has the desired display attributes (bold, italic, white on red)

The kendo.grid.js _tmpl: was modified as follows:

In the "if (!rowTemplate)" section just prior to 
rowTemplate += ">";<br>
this was added
var option = settings.onCloseImplicitRowTag;
if (option) {
    type = typeof option;
    if (type === STRING) {
        rowTemplate += ' ' + option;
    }
}

Hope this is helpful and the concept gets rolled into a future version

Regards,
Richard

No answers yet. Maybe you can help?

Tags
Grid
Asked by
Richard
Top achievements
Rank 1
Share this question
or