Bug, data source fails when there's only one element in an XML file

7 posts, 0 answers
  1. Benjamin
    Benjamin avatar
    3 posts
    Member since:
    Oct 2011

    Posted 22 Oct 2011 Link to this post

    It seems that when there's only one XML element, the DropDownList fails to show it, and instead shows 'undefined' five times. Very odd. No errors in the console.

    UPDATE: It seems each of the five "undefined" entries in the drop down correspond to the 5 xml elements nested within the doc. So its parsing the doc but failing to map to the schema. If I add the 2nd item (a duplicate), it loads them both fine.
  2. Rosen
    Admin
    Rosen avatar
    3253 posts

    Posted 24 Oct 2011 Link to this post

    Hi Benjamin,

    Could you please provide a bit more information about the XML's structure and declaration of the DataSource and DropDownList.

    Greetings,
    Rosen
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. Frantisek
    Frantisek avatar
    2 posts
    Member since:
    Nov 2011

    Posted 04 Nov 2011 Link to this post

    Hi,

    I have similar problem as Benjamin. When I have one item in xml data source, loading into grid fails, but when I get two or more items, grid works fine. I attached 2 printscreens of what I get. There are no errors in console.

    Definition of data source and grid

    var dataSource = new kendo.data.DataSource({
            transport: {
                dataType: "xml",
                read: "xmlDataSource.php"
            },
            schema: {
                type: "xml",
                data: "/items/item",
                model: {
                    fields: {
                        name: "name/text()",
                        code: "code/text()",
                        desc: "desc/text()",
                        price_tax: "price_tax/text()",
                        id_item: "id_item/text()",
                        currency: "currency/text()"
                    }
                }
            },
            pageSize: 100,
            serverPaging: true,
            serverSorting: true
        });
     
        $("#grid").kendoGrid({
            dataSource: dataSource,
            scrollable: true,
            sortable: true,
            pageable: true,
            groupable: true,
            columns: [
            {field: "code", title: "Kód", width: "10px"},
            {field: "name", title: "Název produktu", width: "50px"},
            {field: "desc", title: "Popis", width: "80px"},
            {field: "price_tax", title: "Cena", width: "20px"},
            {field: "amount", title: " ", width: "50px",template: GRID_AMOUNT_INPUT},
            {field: "buy", title: " ", width: "50px",template: GRID_ADDTOCART_BUTTON},
            ]
        });

    When I use dataSource.options.schema.data = "/items" instead of "/items/item", it works with one item in xml file, but not for more. Its weird ...

    Then definition looks like this:

    var dataSource = new kendo.data.DataSource({
            transport: {
                dataType: "xml",
                read: "xmlDataSource.php"
            },
            schema: {
                type: "xml",
                data: "/items",
                model: {
                    fields: {
                        name: "name/text()",
                        code: "code/text()",
                        desc: "desc/text()",
                        price_tax: "price_tax/text()",
                        id_item: "id_item/text()",
                        currency: "currency/text()"
                    }
                }
            },
            pageSize: 100,
            serverPaging: true,
            serverSorting: true
        });
     
        $("#grid").kendoGrid({
            dataSource: dataSource,
            scrollable: true,
            sortable: true,
            pageable: true,
            groupable: true,
            columns: [
            {field: "code", title: "Kód", width: "10px"},
            {field: "name", title: "Název produktu", width: "50px"},
            {field: "desc", title: "Popis", width: "80px"},
            {field: "price_tax", title: "Cena", width: "20px"},
            {field: "amount", title: " ", width: "50px",template: GRID_AMOUNT_INPUT},
            {field: "buy", title: " ", width: "50px",template: GRID_ADDTOCART_BUTTON},
            ]
        });

    Is it a bug or am I doing anything wrong?

    Thanks for help,
    Frantisek.
  4. Rosen
    Admin
    Rosen avatar
    3253 posts

    Posted 04 Nov 2011 Link to this post

    Hi Frantisek,

    In both cases you should use  data: "/items/item" as this is the "path selector" for the item from the root.

    All the best,
    Rosen
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  5. Frantisek
    Frantisek avatar
    2 posts
    Member since:
    Nov 2011

    Posted 04 Nov 2011 Link to this post

    Thanks for the answer.

    I understand what you mean. But when I've one <item> tag in XML file and using data: "/items/item", I'm  getting results as you can see in grid-xmldatasource-with-1-item.jpg. Definition data: "/items/item" works only if I have 2 or more <item> tags in XML file.
  6. Rosen
    Admin
    Rosen avatar
    3253 posts

    Posted 07 Nov 2011 Link to this post

    Hello Frantisek,

    Indeed, you are correct, I was able to observed the described behavior. We managed to address it and the fix will be included in the next version of the library.

    Thank you for reporting 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!
  7. Selvamani
    Selvamani avatar
    4 posts
    Member since:
    Jan 2013

    Posted 07 Feb 2013 Link to this post

    Hi Rosen

    Hi have an issue with binding an xml to grid 
    my sample xml is 

    <id> 
     <r rn="1" sel="0">
      <vw n="address" v="Mycomp" />
      <vw n="description" v="AdminOU" />
      <vw n="identifier" v="1" />
      <vw n="mlouname" v="" />
         <vw n="remarks" v="Administration Unit" />
    </r>
    <r rn="2" sel="0">
        <vw n="address" v="Mycomp" />
      <vw n="description" v="SASDesignOU" />
      <vw n="identifier" v="2" />
      <vw n="mlouname" v="" />
      <vw n="remarks" v="SAS Design  Unit" />
    </r>
     </id>

    each value in the <vw> element in the <r> should be mapped to the column of the grid,  but kendo is not accepting the duplication of <vw> tag inside the <r> element .. can u help me...
Back to Top