jQWidgets Forums

jQuery UI Widgets Forums Grid How to define source datafields when using odata $expand to get related entities?

This topic contains 1 reply, has 1 voice, and was last updated by  delebash 12 years, 3 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author

  • delebash
    Participant

    If I use the the odata parameter $exapnd to get a Primary record with its associated n-1 how do I map/model this in the source dataAdapter or grid?

    Example if Contact is the Primary entity and ContactType is the n-1 and using $expand I get a result like
    "__ENTITIES":[{"__KEY":"196","__STAMP":20,"ID":196,"firstName":"ab","middleName":"ddd","lastName":"eee",
    "ContactType":{"__KEY":"3","__STAMP":2,"ID":3,"name":"Work","contactCollection":{"__deferred":{"uri":"/rest/ContactType(3)/contactCollection?$expand=contactCollection"}}},"addressCollection":{"__deferred":{"uri":"/rest/Contact(196)/addressCollection?$expand=addressCollection"}}}

    Then I define my datafields like so, How do I define ContactType if I want to display ContactType.name in the grid.
    myDataModel = [{
    name : "__KEY"
    }, {
    name : "__STAMP"
    }, {
    name : "ID"
    }, {
    name : "firstName"
    }, {
    name : "middleName"
    }, {
    name : "lastName"
    }]

    Is there a way when defining your datafields model to define related entities?

    I tried just adding ContactType.name to the grid column but that didn’t work.
    columns : [{
    text : 'ID',
    datafield : 'ID'
    }, {
    text : 'First Name',
    datafield : 'firstName'
    }, {
    text : 'Middle Name',
    datafield : 'middleName'
    }, {
    text : 'Last Name',
    datafield : 'lastName'
    }, {
    text : 'Contact Type',
    datafield : 'ContactType.name'
    }

    Not sure the best approach for handling complex data, any help is appreciated


    delebash
    Participant

    I figured it out, just found Examples with nested Json in http://www.jqwidgets.com/jquery-widgets-documentation/documentation/jqxgrid/jquery-grid-datasources.htm

    var data = [{ “empName”: “test”, “age”: “67”, “department”: { “id”: “1234”, “name”: “Sales” }, “author”: “ravi”}];

    // prepare the data
    var source =
    {
    datatype: “json”,
    datafields: [
    { name: ’empName’ },
    { name: ‘age’ },
    { name: ‘id’, map: ‘department>id’ },
    { name: ‘name’, map: ‘department>name’ },
    { name: ‘author’ }
    ]

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.