success callback on dataSource transport read

1 Answer 8260 Views
Data Source
George
Top achievements
Rank 1
George asked on 31 May 2012, 11:06 PM
I can't seem to get the success callback to execute on this datasource. I am getting the data, so I know the call is working, just the success callback is not firing: 

var dsReviewList = new kendo.data.DataSource({
    schema: {
        data: "d",
        model: {
            fields: {
                resID: { type: "number" },
                resDate: { type: "string" },
                description: { type: "string" },
                amount: { type: "number" },
                selected: { type: "boolean" },
                total: { type: "number" }
            }
        }
    },
    transport: {
        read: {
            contentType: "application/json; charset=utf-8",
            type: "POST",
            dataType: "json",
            url: "OWLV2be.asmx/GetReviewReservations",
            success: function (data) {
                alert(data);
            },
            error: function (xhr, error) {
                console.debug(xhr); console.debug(error);
                alert('error');
            }
        },
        parameterMap: function (data, operation) {
            return kendo.stringify(data);
        }
    },
});

Please help, thanks,

George




You June
Top achievements
Rank 1
commented on 28 Oct 2022, 08:17 AM

try with

"complete: function(data) {"

instead of

"success: function(data) {"

1 Answer, 1 is accepted

Sort by
0
Nikolay Rusev
Telerik team
answered on 01 Jun 2012, 07:44 AM
Hello George,

The success callback will be overriden by the one attached from the transport. DataSource have change event which is wired to success of the request and error event that will be triggered if any error occurred for the request.

I would recommend you to use those events instead.

Greetings,
Nikolay Rusev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Engifaar
Top achievements
Rank 1
commented on 01 Jun 2012, 12:05 PM

Hello Sir, I'm accessing an ASP.NET WebServices that return JSON. I can see the data correctly from the server to in FireBUG: (See Below)
 I am unable to fill my grid with my URL data returned.. What is my mistake?

var dataSource = new kendo.data.DataSource({
        transport: {
            read: {
                url: "WebService.asmx/getAllCustomerName",
                type: "POST",
                contentType: "application/json; charset=utf-8",
                dataType: "json"
            }
        },
        schema: {
            data: function (data) {
                alert(data.d);   /*Data Return Successfully*/
                return data.d;
            }
        },
        error: function (e) {
            alert("Error");
        },
        change: function (e) {
            alert("Change");
        },
        requestStart: function (e) {
            alert("Request Start");
        }
    });


    $("#try").kendoGrid({
        dataSource: dataSource, //No data...
        pageable: true,
        sortable: true,
        height: 450,
        scrollable: { virtual: true },
        selectable: true,
        dataBound: function (e) {
            alert("DataBound");
        },
        columns: [
                    { field: "CustomerID", title: "CustomerID" },
                    { field: "FirstName", title: "FirstName" },
                    { field: "LastName", title: "LastName" },
                    { field: "BalancePoint", title: "BalancePoint" }
                ]
    });


My URL return data of json type:--

{"d":"[{\"BalancePoint\":\"2017.000\",\"CustomerID\":\"000\",\"FirstName\":\"AA\",\"LastName\":\"ZX\"},
{\"BalancePoint\":\"224.000\",\"CustomerID\":\"001\",\"FirstName\":\"AB\",\"LastName\":\"ZY\"},
{\"BalancePoint\":\"1094.000\",\"CustomerID\":\"002\",\"FirstName\":\"AC\",\"LastName\":\"ZZ\"}
]"}
George
Top achievements
Rank 1
commented on 01 Jun 2012, 03:49 PM

Ok, that worked (using change: and not success:)

var dsReviewList = new kendo.data.DataSource({
    schema: {
        data: "d",
        model: {
            fields: {
                resID: { type: "number" },
                resDate: { type: "string" },
                description: { type: "string" },
                amount: { type: "number" },
                selected: { type: "boolean" },
                total: { type: "number" }
            }
        }
    },
    transport: {
        read: {
            contentType: "application/json; charset=utf-8",
            type: "POST",
            dataType: "json",
            url: "OWLV2be.asmx/GetReviewReservations"
        },
        parameterMap: function (data, operation) {
            return kendo.stringify(data);
        }
    },
    change: function (data) {
        OWL.readyForCheckout = dsReviewList._data.length;
    },
    error: function (xhr, error) {
        console.debug(xhr); console.debug(error);
    }
});

One think I noticed, I needed a count of the number of entries returned so I tried to use dsReviewList.total(), but this always returned 0, so I am using dsReviewList._data.length; which seems to be correct.

-George

Nikolay Rusev
Telerik team
commented on 04 Jun 2012, 06:55 AM

Hello George,

Indeed total will be available only if returned from server or paging is enabled. Otherwise you will have to take the count from the data, i.e dataSource.data().length(). data() function returns _data.

Regards,
Nikolay Rusev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
George
Top achievements
Rank 1
commented on 04 Jun 2012, 12:23 PM

How would I have the server return the total? 

Engifaar
Top achievements
Rank 1
commented on 04 Jun 2012, 12:35 PM

How to get distinct value from dataSource(Array)? Is there any property in filter to distinct column/Array Value? Please do reply....
 Thank You
Nikolay Rusev
Telerik team
commented on 07 Jun 2012, 06:35 AM

Hello George,

In order to do so you should set serverPaging: true and define/in the schema definition/ which field from the response will contain the total.

The following demo illustrates server paging and have predefined total/for type: "odata"/  in the schema similar to { schema: data: "d.results", total: "d.__count" }. You can inspect the response from the service on paging for more details.
http://demos.kendoui.com/web/grid/remote-data.html

Regards,
Nikolay Rusev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Data Source
Asked by
George
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
Share this question
or