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

How to set type on fields in XML datasource?

3 Answers 233 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Amanda
Top achievements
Rank 1
Amanda asked on 20 Nov 2012, 08:19 PM
I have a grid that is getting its data from XML.  I want to define types (numeric, date, etc.) on the fields.  How do I do this?  I've tried defining my model fields like CARD:  { value: 'CARD/text()', type: 'number' } but that doesn't seem to work.

var xml = '<ROWS><ROW id="1"><CARD>1</CARD><LLINE>1</LLINE></ROW><ROW id="2"><CARD>1</CARD><LLINE>2</LLINE></ROW></ROWS>';
 
$(document).ready(function() {
    $('#gridDiv').kendoGrid({
        columns: [
            {
                field: 'CARD',
                title: 'Card',
                width: 60
            },{
                field: 'LLINE',
                title: 'Line',
                width: 60
            }
        ],
        dataSource: new kendo.data.DataSource({
            type: 'xml',
            data: xml,
            schema: {
                type: 'xml',
                data: '/ROWS/ROW',
                model: {
                    id: 'id',
                    fields: {
                        id:     '@id',
                        CARD:   'CARD/text()',
                        LLINE:  'LLINE/text()'
                    }
                }
            }
        })
    });
});

3 Answers, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 21 Nov 2012, 10:19 AM
Hello Amanda,

Setting the field type via the field declaration should be sufficient in order to convert the value. Here is a small sample which demonstrates this. 

Regards,
Rosen
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Amanda
Top achievements
Rank 1
answered on 21 Nov 2012, 03:09 PM
Yes, that's exactly what I needed.  Thank you!  I don't see that field property in the docs anywhere -- maybe it could be added?
0
Marco
Top achievements
Rank 1
answered on 22 Jan 2014, 01:48 PM
Thanks! I couldn't find the field property either in the docs. I have copied the solution from the link below .

var grid = $('#grid').kendoGrid({
      columns: [
          {
              field: 'CARD',
              title: 'Card',
              width: 60
          },{
              field: 'LLINE',
              title: 'Line',
              width: 60
          }
      ],
      dataSource: new kendo.data.DataSource({
          type: 'xml',
          data: xml,
          schema: {
              type: 'xml',
              data: '/ROWS/ROW',
              model: {
                  id: 'id',
                  fields: {
                      id:     '@id',
                    CARD:   { field: 'CARD/text()', type: "number" },
                      LLINE:  'LLINE/text()'
                  }
              }
          }
      })
  }).data("kendoGrid");

Tags
Data Source
Asked by
Amanda
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Amanda
Top achievements
Rank 1
Marco
Top achievements
Rank 1
Share this question
or