I have an issue, when I bind data with kendo to a Table I'm using a kendo.data.DataSource object and I'm binding to a table like:
<table class="myClass" id="myTable">
<thead>
<tr>
<th data-bind="visible:Name">Name.Title"</th>
<th data-bind="visible:Type">Type.Title"</th>
<th data-bind="visible: DateAdded">"CreatedDate.Title"</th>
</tr>
</thead>
<tbody id="contactsListView" data-role="listview"
data-bind="source: ListViewSource"
data-template="Template"></tbody>
</table>
on JS I am filling like this:
ListViewSource: new kendo.data.DataSource({
serverPaging: true, // <-- Do paging server-side.
serverSorting: true, // <-- Do sorting server-side.
transport: {
read: {
data: function () {
return globalVariableWithObjectList;
}
}
},
schema: {
data: function () {
return globalVariableWithObjectList;
}
}
}),
and it works for fill table on the first load, but if with some actions I add or delete an element It does not refresh on the table. I'm trying to refresh with:
ListViewSource.read();
It works when I have the kendo.data.DataSource like this:
contactsListViewSource: new kendo.data.DataSource({
serverPaging: true, // <-- Do paging server-side.
serverSorting: true, // <-- Do sorting server-side.
transport: {
read: {
url: myUrl,//Where I'm getting the data
dataType: "json",
type: "POST"
}
},
pageSize: 5,
sort: { field: "CreatedDate", dir: "desc" },
schema: {
data: function () {
return globalVariableWithObjectList;
}
}
}),
I am trying to reduce ajax numerous calls with only one when multiple data to update is needed, and storing data in global variables so that I can use them later. But the read() function for kendo.data.DataSource only refresh table data when it calls for an ajax request and non when I try to get data from the global variable, does anyone knows how can I make it work while reading from the variable ?
Use contactsListViewSource.add(newRecord); for adding new records to the data source, it will automatically bind to HTML list (MVVM) and display it.
Call contactsListViewSource.sync() to send data to server. contactsListViewSource.sync() will call transport.create method if new records are added.
Working example: ListView MVVM