Welcome Guest, Not a member yet? Register   Sign In
FlexiGrid problem with formatting the JSON
#1

[eluser]Unknown[/eluser]
Hi,

I have a web method that returns a JSON string thats not in the format that flexiGrid requires so i created a method to convert this into the right format and call this in the preprocess section of the flexi grid.

I am receiving synatx error when i try to create the flexigrid and i can't see where this would be happening in my code.

my JSON file that i am converting is in the following format:

{"Response":[{"Total":1,"Status":"Success"},{"Total":4,"Status":"Success"},{"Total":6,"Status":"Success"}],"Status":1}

my conversion method is:

Code:
function formatResults(data) {
        var rows = Array();
        var count = 0;
        for (index in data.Response) {
            count++;
            rows.push({ id: count, cell: [testData.Response[index].Total, testData.Response[index].Status] });
        }

        return {
            total: count,
            page: 1,
            rows: rows
        }
    };

Can anyone see any obvious errors in the code below:

Code:
$.ajax({
            type: "POST",
            url: "Login.aspx/GetCredentials",
            data: "{}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (msg) {
                var data = $.parseJSON(msg.d);
                var p = [
                        { name: 'username', value: data.User },
                        { name: 'password', value: data.Pass }
                ]
                $("#flex1").flexigrid({
                    url: "http://localhost/test/test.asmx/Getdata",
                    preProcess: formatResults,
                    dataType: 'json',
                    params: p,
                    colModel: [
                        { display: 'Total', name: 'Total', width: 190, sortable: true, align: 'left' },
                        { display: 'Status', name: 'Status', width: 150, sortable: true, align: 'left' },
                        ],
                    searchitems: [
                        { display: 'Total', name: 'AuthenticationTimestamp' }
                        ],
                    onError: function (jqXHR, textStatus, errorThrown) {
                        alert("flexigrid failed " + errorThrown);
                    },

                    sortname: "Total",
                    sortorder: "asc",
                    usepager: true,
                    title: "Report",
                    useRp: true,
                    rp: 10,
                    showTableToggleBtn: false,
                    resizable: false,
                    width: 700,
                    height: 370,
                    singleSelect: true
                }
                );
            },
            error: function (jqXHR, textStatus, errorThrown) {
                alert(errorThrown);
            }
        });

Thanks




Theme © iAndrew 2016 - Forum software by © MyBB