I am trying to add a page field to my datasource results. I am using schema.parse to align field names, add a couple of fields, and some basic data manipulation. One of the fields I want to add is the current page of the datasource. I can use the datasource.page() method but it only updates once the datasource has returned the data and apparently schema.parse happens before that. I am looking for another way to either access a parameter of the datasource or somehow calculate the current page using the skip/total parameters.
var ds = new kendo.data.DataSource({
transport: {
read: {
url: PRODUCTAPI,
data: getOfferData()
}
},
serverPaging: true,
pageSize: 50,
schema: {
data: "results",
total: "count",
model: { id: "id" },
parse: function(response) {
var myData = {};
var results = [];
prodcnt = response.results.length;
for (var i = 0; i < response.results.length; i++) {
var prod = response.results[i];
var product = {
id: prod.id,
category: prod.category,
page: ??? // this is where I would like to know this.page()
// other fields here
prev_record: null,
next_record: null
};
results.push(product);
}
// do other stuff here
return myData;
}
},
change: function(e) {
// I can access page() from here!
var pg =this.page();
console.log("page: " + pg);
}
});
EDIT: What I am doing is this. Using data-click on the listview I am calling a detail view. The detail view accesses the UID of the clicked element and fetches the entire record from the dataset using getByUID. From teh detail view, the user can use a Next/Prev button to page through the detail records without returning to the listview. This works fine but if the user reaches the bounds of the datasource, I need to know what page they started on in order to manually call datasource.page(x). I have tried reaching back through the datasource object with no luck. I thought another approach would be to include it in the data at runtime.
You cannot get it through the dataSource object. The only possible ways are by logging that page by:
- overriding the parameterMap function - which I do not recommend
- capturing the click on the pager button and get the number from the HTML of the button that was click and log it in a variable