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
400
what data format igGrid is expected from web service? databinding successful only with .ajax call first, but not direct binding call
posted

Hi all,

I encountered an error when binding data returned from web service to igGrid. The error is occurred in ig.ui.min.js when JSON.parse(s) is called.

stringToJSONObject:function(s){var data={};try{data=JSON.parse(s)}catch(e)

The message is "there was an error in parsing/evaluating json string: Syntax Error"

I have the following from code on my server side:

List<MyTransaction> Transactions = new List<MyTransaction>

{ new MyTransaction{ TransactionID=12235, PlanID=63, Premium=225f},

new MyTransaction{ TransactionID=12236, PlanID=64, Premium=256f},

new MyTransaction{ TransactionID=12237, PlanID=77, Premium=355f}

};

[WebMethod]

public List<MyTransaction> GetAllTransactions()

{return Transactions;}

 In my aspx page (Version 1) I have:

var url = "/Vertex/CarService.asmx/GetAllTransactions";
       
        var json = new $.ig.DataSource({  type: "json", dataSource: url });

       
            $("#igGrid").igGrid({
                virtualization: false,
                autoGenerateColumns: false,
                jQueryTemplating: false,
              
                columns: [
            { headerText: "TransactionID", key: "TransactionID", dataType: "number", width: "150px" },
            { headerText: "PlanID", key: "PlanID", dataType: "number", width: "120px" },
            { headerText: "Premium", key: "Premium", dataType: "number", width: "400px" }
           ],

                dataSource: json,
                responseDataKey: "d",
                scrollbars: true,
                height: '800px',
                features: [
            {
                name: 'Paging',
                pageSize: 20
            },
            {
                name: 'Sorting'
            },
            {
                name: 'Filtering',
                filterDropDownItemIcons: false,
                filterDropDownWidth: 200
            }
           ]
            });
        }

 

However, if I change my aspx into the following(version 2), the data binding is OK. That means using ajax call to get data first, then data binding is OK.

What am I missing in version 1? should I use  responseDataKey: "d" option?
 

$(function () {

        $.ajax({

            type: "POST",

            url: "/Vertex/CarService.asmx/GetAllTransactions",

            data: "{}",

            contentType: "application/json; charset=utf-8",

            dataType: "json",

            success: function (response) {

                records = response.d;

                $("#igGrid").igGrid({
                    virtualization: false,
                    autoGenerateColumns: false,

                    columns: [
            { headerText: "TransactionID", key: "TransactionID", dataType: "number", width: "150px" },
            { headerText: "PlanID", key: "PlanID", dataType: "number", width: "120px" },
            { headerText: "Premium", key: "Premium", dataType: "number", width: "400px" }
           ],

                    dataSource: records,

                    scrollbars: true,
                    height: '400px',
                    features: [
            {
                name: 'Paging',
                type: "local",
                pageSize: 5
            },
            {
                name: 'Sorting'
            },
            {
                name: 'Filtering',
                type: 'local',
                filterDropDownItemIcons: false,
                filterDropDownWidth: 200
            }
           ]
                });

            },

            failure: function (msg) {
                $('#dailyTransaction').text(msg);
            }

        });

    });

 

Betty

Parents Reply Children
No Data