success callback on dataSource transport read

8 posts, 0 answers
  1. George
    George avatar
    18 posts
    Member since:
    Aug 2007

    Posted 31 May 2012 Link to this post

    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




  2. Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    2284 posts

    Posted 01 Jun 2012 Link to this post

    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!
  3. Kendo UI is VS 2017 Ready
  4. Engifaar
    Engifaar avatar
    15 posts
    Member since:
    May 2012

    Posted 01 Jun 2012 Link to this post

    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\"}
    
    ]"}
  5. George
    George avatar
    18 posts
    Member since:
    Aug 2007

    Posted 01 Jun 2012 Link to this post

    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

  6. Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    2284 posts

    Posted 04 Jun 2012 Link to this post

    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!
  7. George
    George avatar
    18 posts
    Member since:
    Aug 2007

    Posted 04 Jun 2012 Link to this post

    How would I have the server return the total? 

  8. Engifaar
    Engifaar avatar
    15 posts
    Member since:
    May 2012

    Posted 04 Jun 2012 Link to this post

    How to get distinct value from dataSource(Array)? Is there any property in filter to distinct column/Array Value? Please do reply....
     Thank You
  9. Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    2284 posts

    Posted 07 Jun 2012 Link to this post

    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!
Back to Top
Kendo UI is VS 2017 Ready