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
65
Binding OData to Ignite UI Grid
posted

Hi,

I am new to Ignite UI and am trying to follow the online documentation on binding data via OData datasource.

1. I do see data returned back (alert does show the first record) as also I tried populating a normal HTML dropdown, but the Grid does NOT populate.

Any help would be welcome.

The code (In my past few days I have tried a few things- so maybe there is some duplication/redundancies).

Please Note - the "alert(data.d[0].Name);" returns the first record (and hence my belief that data is being returned successfully)

//*******Grid code that does not populate

var svc_url1 = "AdventureWorksDataService.svc/Products?$select=ProductID,Name";                                

            $.ajax({
                type: 'GET',
                dataType: 'json',
                contentType: 'application/json; charset=utf-8',
                url: svc_url1,
                beforeSend: function (xhr) {
                    xhr.setRequestHeader("Accept", "application/json;odata=verbose");
                    xhr.setRequestHeader("MaxDataServiceVersion", "3.0");
                },
                success: function (data) {
                    alert(data.d[0].Name);
                    
                    $('#tableProducts').igGrid({
                        height: '500px',
                        width: '800px',
                        responseDataKey: 'd.results',
                        dataSource: svc_url1,
                        autoGenerateColumns: false,
                        columns: [
                            { headerText: 'ID', key: 'ProductID', dataType: 'number' },
                            { headerText: 'Name', key: 'Name', dataType: 'string' }
                        ],
                    });
                },
                error: function () {
                    alert("Failed to retrieve !");
                }
            });

//*************end of code

//**** This code correctly populates a normal HTML Select

var svc_url = "AdventureWorksDataService.svc/Products?$select=ProductID,Name";
            $.ajax({
                type: "GET",
                dataType: "json",
                contentType: 'application/json; charset=utf-8',
                url: svc_url,
                beforeSend: function (xhr) {
                    xhr.setRequestHeader("Accept", "application/json;odata=verbose");
                    xhr.setRequestHeader("MaxDataServiceVersion", "3.0");
                },
                success: function (resp) {
                    $.each(resp.d, function () {
                        $("#lstCategories").append($("<OPTION></OPTION>").val(this['ProductId']).html(this['Name']));
                    });
                },
                error: function () {
                    alert("Failed to retrieve Category items!");
                }
            });

//*****end of code

Parents Reply Children
No Data