This is a migrated thread and some comments may be shown as answers.

Kendo ListView - SignalR - Edit & Update client datasource

4 Answers 89 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Matt
Top achievements
Rank 1
Matt asked on 11 Dec 2013, 03:45 PM
I could have two clients editing the same page and want the changes adjusted immediately without refreshing the data source.

The listview is setup fairly normally. It feeds of a data source and in turn sends updates through a MVC controller update.

When the MVC action processes the update it notifies connected users to the group of the change(s) to items. This notification is the same response that the JSON Result responds with effectively.

Updating all clients is close to working:
Scenario 1: Client 1 and 2 goto the same page. Client 1 edits a field and those changes are reflected on client 2's screen.
Scenario 2: Client 1 and 2 edit the same row. Any saved changes by either are updated to the others edit fields.

The problem im getting is when Client 2 begins editing a different row. When it goes to Client 1 it is more seen as the edit state of the data row. A little more challenging to understand what i mean.
So yes... im more hiting my way through the data source to have my changes there. The SignalR function will seek out the row(s) to update and run:

01.for (var i = 0; i < menuItems.length; i++)
02.{
03.    var item = menuItems[i];
04.    var dataSourceItem = this.findById(item.Id);
05.    if (!dataSourceItem) { continue; }
06. 
07.    var thumbArray = new kendo.data.ObservableArray(item.Thumbs)
08.    dataSourceItem.set("WebName", item.WebName);
09.    dataSourceItem.set("WebDescription", item.WebDescription);
10.    dataSourceItem.set("Thumbs", thumbArray);
11.    //however each item is now dirty ... and i don't want to send off them again to be saved.
12.    dataSourceItem.dirty = false;
13.}
14.if (this.dataSource.hasChanges()) {
15.    //this should always be a no now.
16.    console.log("has changes");
17.}
this.findById is digging through the kendoDataSource.data() method and returning the correct item.

How can I update the data item in the data source and have it think its the pristine saved version after the signalr update? As client 1 and 2 sort of move into a protective - only display saved changes mode once editing has started. Clicking on update on a modified row by a different client will have the correct signalr pushed values but they are not on the item display template.

Best Regards,
Matt

4 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 12 Dec 2013, 09:15 AM
Hi Matthew,

I prepared a sample application which shows a possible implementation. It is using the grid but the same should work with the listview.

Regards,
Atanas Korchev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Matt
Top achievements
Rank 1
answered on 12 Dec 2013, 03:30 PM
dataItem.accept(item);
dataItem.trigger("change");

I presume it was those two lines that I was after. My computer is installing .net 4.5.1 at the moment so i cant run the project to confirm just yet. But copying those lines instead of have dataItem.set("field", value) etc ... i didn't know 'accept' did that, which is useful for one of my other problems.

It updates properly from between client 1 and client 2 as before. The problem only occurs once both clients have edited the same row. The display template displays the listview's 'last saved' version only. Clicking edit on that same row and the row will display the pushed changes by SignalR in the edit template which continues the next 'save changes' or 'cancel' steps. Editing any other row that hasnt been modified by the opposite client still works.

Currently using the internal build v2013.3.1122. I will test out the sample project shortly.
0
Matt
Top achievements
Rank 1
answered on 12 Dec 2013, 03:44 PM
Thanks Atanas Korchev

The grid is doing what I expect. I'll test it to see if it does the same thing with the listview
0
Matt
Top achievements
Rank 1
answered on 12 Dec 2013, 04:36 PM
List view templates - display & edit have the expected current state (in your attached project)... which means that my code is the one doing something odd.

dataItem.accept(item);
dataItem.trigger("change");

The lines above are always firing from a change by another client on signalr. Ive checked my build version on the project and that is fine as well. I'll keep playing with it.
Tags
ListView
Asked by
Matt
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Matt
Top achievements
Rank 1
Share this question
or