Domanda

I have the following code and I am trying to get the count of returned records without having to issue a second fetch() command:

dsOffers = new kendo.data.DataSource({
    transport: {
        read: {
            url: PRODUCTAPI,
            data: getOfferData()
        }
    },
    serverPaging: true,
    pageSize: 50,
    schema: {
        data: "results",
        total: "count",
        model: { id: "id" }
    }
})
.bind("error", namespace.dataSource_error);

dsOffers.total(); // returns 0

// if I use this, my API is hit twice
dsOffers.fetch(function() {
    console.log(dsOffers.total()); // returns 3
});
È stato utile?

Soluzione

The problem is that it takes time loading the data (it happens asynchronously -in background/parallel-). If you print it just after the initialization you actually don't have the data available.

This is the correct behaviour.

If you don't want to do the second fetch you should print it in the dataBound event.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top