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

Autosync to track changes in only certain fields, not all

2 Answers 453 Views
Grid
This is a migrated thread and some comments may be shown as answers.
ICT
Top achievements
Rank 1
ICT asked on 12 Jun 2013, 01:05 PM
Hi,

 I have an editable grid showing data from DataSource and updating the backend with autosync. So far everything has gone quite smoothly and I'm generally pleased with Kendo grid filtering capabilities. I, however, have an issue with autosync. I want to disable some columns from autosync.

The simplified model of the grid is two columns, “word1” and “word2”. In addition to that, I will have several boolean columns that I use for filtering. I have several such boolean columns. Some of them are generated on the backend and some of them I want to modify on-the-fly in client.

One such filter is to flag rows that have the same value in columns “word1” and “word2”.

I have tested iterating over data and setting the boolean column. The current test code is as follows:

01.$("#test").click(function() {
02.    for (var i=0; i<DS.data().length; i++) {
03.        var row = DS.at(i);
04.        if(row.word1==row.word2) {
05.            console.log("Words are the same: "+row.word1+"=="+row.word2)
06.            row.set("ok", true);
07.        } else {
08.            console.log("Words are not the same: "+row.word1+"!="+row.word2)
09.            row.set("ok", false);
10.        }
11.    }
12.});
When I run the function, it updates the column as I want it to. But, here's the issue; it
sometimes generates a lot of traffic for the backend because many values in the boolean column might change. This is not wanted, since the boolean columns are only temporary for the user to get a glance at the data. Autosync should only track columns word1 and word2. The changes in other columns should go unnoticed by autosync.

Finally, my two questions:

1) Is there a way to define which fields are monitored by autosync?

2) Is there a way to define which fields are sent to backend after editing? I do not need the contents of temporary boolean columns on the backend, so when user changes, say, word1, I am only interested in getting values of word1 and word2, not the other columns.

2 Answers, 1 is accepted

Sort by
0
Accepted
Alexander Valchev
Telerik team
answered on 14 Jun 2013, 08:26 AM
Hello Janne,

Straight to your questions:
  1. Is there a way to define which fields are monitored by autosync?
    This is not supported. When autoSyncing is enabled, data source would automatically saves any changes made in the data items by calling the sync method.
  2. Is there a way to define which fields are sent to backend after editing?
    Yes, you can do that in the parameterMap function of the transport. This however will not reduce the Ajax requests which the DataSource issues. You should have in mind that the data source keeps track of the changed records, not fields. This means that if you change the boolean field of record A, the data source will attempt to send the whole record A (data source does not know the exact field of record A that was changed).

If your aim is to not sync the changes when boolean fields are updated, but only when the user changes field "word1" or "word2" I suggest the following approach:
  • turn off the AutoSync
  • hook up to the change event of the DataSource
  • from the event parameters you can retrieve information about the action (you need "itemchange") and field name. If one of the aforementioned field was changed, you may call the sync method to submit all the pending changes.
change: function(e) {
    e.action; //"itemchange" is needed
    e.field; //field name - "word1" or "word2"
    this.sync(); //will sync the changes
}

I hope this will help.

Regards,
Alexander Valchev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
ICT
Top achievements
Rank 1
answered on 14 Jun 2013, 12:02 PM
Thank you!

This helped a lot. By using the change event as you proposed I was able to do what I want.

By the way, there's something odd with the forum -- "mark as answered" gives a server error.
Tags
Grid
Asked by
ICT
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
ICT
Top achievements
Rank 1
Share this question
or