Hi,
I would like to have a private method that creates a Datasource to be used. This method can create a datasource either with a data object to send to the URL or one without a data object to send to the URL.
How can I go about achieving this?
ChangeGridDataSource: function (newDatasourceUrl, gridName, dataToSend) {
// Sets the grid to a new datasource and forces it to read
var gridId;
if (gridName[0] !== '#') {
gridId = '#' + gridName;
} else {
gridId = gridName;
}
var newDataSource = new kendo.data.DataSource({
transport: {
read: {
url: newDatasourceUrl,
type: 'POST',
dataType: 'JSON'
}
},
pageSize: 20,
schema: {
model: {
fields: {
// the model fields have to specified that it is of a date type object.
dSECSYSTimeStampDate: { type: 'date' },
dExecutedDateValue: { type: 'date' },
dEffectiveDateValue: { type: 'date' }
}
},
data: 'Data',
parse: function (response) {
// This will parse the dates and transform it into the proper date format. This is done
// after the date has been retrieved in a JSON format. This will allow the formatting of the dates
// to be done in the grids.
return Transactions.Methods.ParseDatesFromKendoGrid(response);
},
total: function (response) {
return response.Total;
}
}
});
if (typeof dataToSend !== 'undefined') {
// Does not seem to work.
newDataSource.transport.read.data = dataToSend;
}
console.log(newDataSource);
console.log(dataToSend);
$(gridId).data('kendoGrid').setDataSource(newDataSource);
},
I have the above and the line 'newDataSource.transport.read.data = dataToSend' doesn't seem to work for some reason. Is there a method that I can call or a different property that can be used to change a Data Object to send in side the data source?