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

Dynamic columns generation with Kendo grid jsp tag

1 Answer 271 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Preeti
Top achievements
Rank 1
Preeti asked on 23 Aug 2013, 08:08 AM
Hi, I have been working on a project where we have to generate the columns dynamically depending on the data coming from Server. We are using Kendo JSP taglib, so using java scriptlet to iterate over the list passed as model attribute to the JSP. Code snippet is as following:

 
<kendo:grid-columns>
     <% 
     
     List fieldsList =  (ArrayList)request.getAttribute("columnArr"); 
     List columnsList = (ArrayList)request.getAttribute("fieldsArr");
     String colName = "";
     String fieldName = "";
     for(int i=0;i<columnsList.size();i++){
      colName = columnsList.get(i);
      fieldName = fieldsList.get(i);
      System.out.println("Col and Field values are:::"+colName+","+fieldName);
      %>          
      <kendo:grid-column title="<%=colName %>"
       field="<%=fieldName %>" headerAttributes="style=\"overflow: visible; white-space: normal;font-weight: bold;\""  />
     <%} %>         
       
     </kendo:grid-columns>

Above code works fine if I use hard coded values in title and field attributes. but when I use variables as shown in above snippet, I get the following exception at runtime:
org.apache.jasper.JasperException: /WEB-INF/views/dashboardWidget.jsp(37,6) Unknown attribute type (String) for attribute title.
 at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
 at org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
 at org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:236)
 at org.apache.jasper.compiler.Validator$ValidateVisitor.checkXmlAttributes(Validator.java:1164)
 at org.apache.jasper.compiler.Validator$ValidateVisitor.visit(Validator.java:821)
 at org.apache.jasper.compiler.Node$CustomTag.accept(Node.java:1530)
 at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2361)
 at org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2411)

Any idea why Title and field attribute are not accepting String variable as value? I have seen the Tag lib for Kendo:grid-column, title has type as String.
<attribute>
            <description>The text that is displayed in the column header cell. If not set the field is used.</description>
            <name>title</name>
            <rtexprvalue>true</rtexprvalue>
            <type>String</type>
        </attribute>
Please also let me know if there is some other way to generate columns dynamically without using scriptlet.
Thanks & Regards,
Preeti

1 Answer, 1 is accepted

Sort by
0
Nikolay Rusev
Telerik team
answered on 27 Aug 2013, 08:33 AM
Hello Preeti,

The expressions should be working properly. I've just tried the following in the JSP demos site that is distributed with every release and is working just fine.

<%
String columnTitle = "My Custom Title";
String columnField = "productName";
%>
    <kendo:grid name="grid" pageable="true" groupable="true" sortable="true" filterable="true">
        <kendo:grid-columns>
            <kendo:grid-column title="<%=columnTitle %>" field="<%=columnField %>" />
            <kendo:grid-column title="Unit Price" field="unitPrice" format="{0:c}" />
            <kendo:grid-column title="Units In Stock" field="unitsInStock" />
        </kendo:grid-columns>
        <kendo:dataSource pageSize="10">
             <kendo:dataSource-schema>
                <kendo:dataSource-schema-model>
                    <kendo:dataSource-schema-model-fields>
                        <kendo:dataSource-schema-model-field name="productName" type="string" />
                        <kendo:dataSource-schema-model-field name="unitPrice" type="number" />
                        <kendo:dataSource-schema-model-field name="unitsInStock" type="number" />
                    </kendo:dataSource-schema-model-fields>
                </kendo:dataSource-schema-model>
            </kendo:dataSource-schema>
            <kendo:dataSource-transport>
                <kendo:dataSource-transport-read url="${transportReadUrl}"/>
            </kendo:dataSource-transport>
        </kendo:dataSource>
    </kendo:grid>

Regards,
Nikolay Rusev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Preeti
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
Share this question
or