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

help getting grid work work with XML datasource

2 Answers 212 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Lee
Top achievements
Rank 1
Lee asked on 27 Feb 2012, 02:43 PM
Using the example set out in the following page: 

http://demos.kendoui.com/web/grid/hierarchy.html

I have tried to get this to use XML instead of oData.  I get "a.replace is not a function" and "a is not defined" javascript errors.

I have managed to get the customers working but I do not know how to link the orders XML file.  I think the problem is with the line:   filter: { field: "customer", operator: "eq", value: "id/text()" }  but I cannot find any examples of the Grid using XML, and do not know what to put for the "value" to get this to match up to the value of the "id" node in the customers XML file - can anyone help?

$(document).ready(function() {
    var element = $("#grid").kendoGrid({
 
         
       dataSource: new kendo.data.DataSource({
           type: "xml", // specifies data protocol
           pageSize: 6, // limits result set
           serverPaging: true,
           serverSorting: true,                       
           transport: {
            read: "customers.xml"
           },
            schema: {
                type: "xml",
                data: "/Customers/Customer",
                model: {
                    fields: {
                        id: "id/text()",
                        surname: "surname/text()",
                        forename: "forename/text()",
                        email: "email/text()"
                    }
                }
            }   
          }),
        height: 450,
        sortable: true,
        pageable: true,
        detailInit: detailInit,
        dataBound: function() {
            this.expandRow(this.tbody.find("tr.k-master-row").first());
        },
        columns: [{
                field:"id",
                filterable: false
            },
            "surname",
            "forename",
            "email"
        ]
    });
});
 
function detailInit(e) {
    $("<div/>").appendTo(e.detailCell).kendoGrid({
        dataSource: {
            type: "xml",
            transport: {
                read: "orders.xml"
            },
            schema: {
                type: "xml",
                data: "/orders/order",
                model: {
                    fields: {
                        id: "id/text()",
                        net: "net/text()",
                        vat: "vat/text()",
                        dispatched: "dispatched/text()"
                    }
                }
            },  
                                 
            serverPaging: true,
            serverSorting: true,
            serverFiltering: true,
            pageSize:6,
            filter: { field: "customer", operator: "eq", value: "id/text()" }
        },
        scrollable: false,
        sortable: true,
        pageable: true,
        columns: [ "id", "net", "vat", "dispatched" ]
    });
}

2 Answers, 1 is accepted

Sort by
0
Juan
Top achievements
Rank 1
answered on 26 Mar 2012, 08:02 PM
Hi, I have the same problem, somebody could resolve it ???

                   function detailInit(e) {
                        var strEmpty = "";
                        alert("e.data.PG_Id: -" + e.data.PG_Id + "-");

                        var ProdGrpProdDataSource = new kendo.data.DataSource({
                            transport: {
                                read: {
                                    type: "POST",
                                    dataType: "xml",
                                    url: readProdGrpProductUrl,
                                    data: { strProdGroup: strEmpty }
                                }
                            },
                            schema: {
                                type: "xml",
                                data: "Product_Groups/Product_Group",
                                model: {
                                    fields: {
                                        ProdGroup_id: "PG_Id/text()",
                                        Product_id: "Product_id/text()",
                                        Product_Desc: "Product_Desc/text()"
                                    }
                                }
                            },
                            serverPaging: true,
                            serverSorting: true,
                            serverFiltering: true,
                            pageSize: 6,
                            filter: { field: "ProdGroup_id", operator: "eq", value: e.data.PG_Id }
                        });

This example show the data correct, in "alert("e.data.PG_Id: -" + e.data.PG_Id + "-")" 
, but it does filter the data in child grid.


0
Brad
Top achievements
Rank 1
answered on 13 Aug 2012, 08:47 PM
How your XML is arranged is what really matters here.

For example:
<book cover="javascript-the-good-parts.png">
An inline field such as this one must be described using '@fieldname'

Where as:
<title>JavaScript: The Good Parts</title>
A field with its own xml tag such as this one must be described using 'fieldname/text()'

Not sure if this is your issue without seeing your XML though.
Tags
Grid
Asked by
Lee
Top achievements
Rank 1
Answers by
Juan
Top achievements
Rank 1
Brad
Top achievements
Rank 1
Share this question
or