Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
190
oData - orderBy child collection
posted

If my oData includes a child (in this case state), and I want to be able to group by the state name.   Unfortunately with the code I presently have below, when grouping by state, it passes $orderby=state+asc,  this causes an error.   I would need it to pass $orderby=state/name+asc.   Is there a way to code the grid to do this?

oData & grid code below:

{

"odata.metadata": "http://localhost:63609/odata/$metadata#EscheatmentsOData",
"odata.count": "1",
"value": [
{
"state": {
"id": 1,
"abbreviation": "AL",
"escheatmentname": "STATE OF ALABAMA",
"name": "Alabama",
"territory": false,
"updateUser": "SeedData",
"updateTime": "2016-05-18T15:44:03.103"
},
"status": {
"id": 1,
"name": "NEW",
"description": "Auto-assign when property record first shows up in the R07306",
"updateUser": "SeedData",
"updateTime": "2016-05-18T15:44:09.583"
},
"address": {
"id": 1,
"firstName": "FirstNameVal",
"middleName": "MiddleNameVal",
"lastName": "LastNameVal",
"streetAddress1": "Street1Val",
"streetAddress2": "Street2val",
"streetAddress3": "street3val",
"city": "cityval",
"zip": "zipval",
"updateUser": "corp\\test",
"updateTime": "2016-05-25T00:00:00"
},
"comments": [],
"id": 1,
"year": 2016,
"cycleStartDate": "2016-01-01T00:00:00",
"cycleEndDate": "2016-12-31T00:00:00",
"accountNumber": "123456",
"accountValue": 100,
"taxId": "123456789",
"birthDate": "1920-06-20T00:00:00",
"dealerBranch": "DealerBranchValue",
"planType": "PlanTypeValue",
"socialCode": "SocialCodeValue",
"deathDate": null,
"desceased": false,
"fiduciary": false,
"regLine1": "ReqLine1Value",
"regLine2": "ReqLine2Value",
"regLine3": "ReqLine3Value",
"regLine4": "ReaLine4Value",
"regLine5": "ReqLine5Value",
"regLine6": "ReqLine6Val",
"build": "BuildVal",
"checkNumber": "CheckNumberVal",
"dollarAmount": 100,
"shareAmount": 200,
"eligibleDate": "2016-06-20T00:00:00",
"establishedDate": "2016-01-05T00:00:00",
"fundNumber": "FundNumberVal",
"lastContactDate": "2016-05-25T00:00:00",
"originalRunDate": "2016-05-25T00:00:00",
"lastRunDate": "2016-05-25T00:00:00",
"late": true,
"yearsLate": 5,
"ddLetterDate": "2016-05-01T00:00:00",
"propertyType": "1",
"rpoDate": "2016-01-01T00:00:00",
"checkDate": "2016-01-02T00:00:00",
"stateCutOffDate": "2016-01-03T00:00:00",
"stateDormancy": 0,
"stateDueDate": "2016-12-15T00:00:00",
"forceIndicator": false,
"updateUser": "corp\\test",
"updateTime": "2016-05-25T00:00:00"
}
]
}

Grid:

///*----------------- Instantiation -------------------------*/
$("#grid").igGrid({
    virtualization: false,
     dataSource: "/odata/EscheatmentsOData?$expand=state,status,address",
     primaryKey: "id",
        restSettings: {
                update: { url: "/api/Escheatmentsapi/" },
                remove: { url: "/api/Escheatmentsapi/" },
                create: { url: "/api/Escheatmentsapi/" }
        },
    autoGenerateColumns: false,
    autoGenerateLayouts: false,
    localSchemaTransform: true,
    responseDataKey: "value",
    renderCheckboxes: true,
    columns: [
        {
            headerText: "Id", key: "id", dataType: "number"
        },
        {
            headerText: "State", key: "state", dataType: "object", formatter: function (val) { return val.name; }
        },
        {
            headerText: "Year", key: "year", dataType: "number"
        },
         {
             headerText: "Fund", key: "fundNumber", dataType: "number"
         },
        {
            headerText: "Account No", key: "accountNumber", dataType: "string"
        },
        {
            headerText: "Tax Id", key: "taxId", dataType: "string"
        },
        {
            headerText: "Check No", key: "checkNumber", dataType: "number"
        },
        {
            headerText: "Description", key: "planType", dataType: "string"
        },
        {
            headerText: "Status", key: "status", dataType: "object", formatter: function (val) { return val.name; }
        },
        {
            headerText: "Value", key: "dollarAmount", dataType: "string"
        }
    ],
    width: "100%",
    features: [
        {
            name: "Paging",
            type: "remote",
            pageSize: 10,
            recordCountKey: "odata.count"
        },
        {
            name: 'GroupBy',
            columnSettings: [

            {
                columnKey: "year",
                isGroupBy: true,
                dir: "asc"
            }
            ]
        }
 
 
    ]
});
  • 29417
    Verified Answer
    Offline posted

    Hello Brian, 

    Thank you for posting in our forum.

     By default there’s no  option in the grid that can re-define the generated url params.

    You could however use the urlParamsEncoded setting on the igDataSource:

    http://www.igniteui.com/help/api/2016.1/ig.datasource#options:settings.urlParamsEncoded

     And in it change the sortingParams’s $orderby value when a column is grouped.

    For example:

    var myUrlParamsEncoded = function (item, params) {

                    params.sortingParams.$orderby = "CustomName asc";

    }

    Which would let you change the orderBy query string before the request is send to the server.

     

    Let me know if that would solve your issue.

                   

    Best Regards,

    Maya Kirova

    Infragistics, Inc.

    http://es.infragistics.com/support