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

Observable Object vs setDataSource

1 Answer 124 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Andrew
Top achievements
Rank 1
Andrew asked on 03 May 2013, 02:16 PM
I wanted to use observable object for my grid, hoping that the performance would be better then what i was getting before.
but i am not sure if it is. I also am confused about the usage.
It seams to be pretty much the same thing.

[I use TypeScript, that's why the code looks a little bit different to pure JS]

When i add a new item.
With the old way i did something like this:
static gridItems: cGridItem[] = [];
 
gridItems.push(item);
 
var grid = $("#grid").data("kendoGrid");
grid.setDataSource(gridItems);
grid.dataSource.read();
then i changed it to observable object way like this:

// Define a DataSource
    static gDataSource = new kendo.data.DataSource({
        data: tsDataManager.gridItems
    });
 
    // Create an observable object.
    static vm = kendo.observable({
        items: tsDataManager.gDataSource
    });
 
tsDataManager.gDataSource.add(item);
Can't see any performance differences.

The weird thing is when i try to edit the items.
In the old way i did this:
var grid = $("#vmGrid").data("kendoGrid");
var item = grid.dataSource.get(id);
item.TimeStamp = tStamp;
               item.Close = aInfo.Last;
               item.Price = aInfo.Last;
               item.NetChange = aInfo.Net;
               item.AskPrice = aInfo.AskPrice;
               item.AskSize = aInfo.AskSize;
               item.BidPrice = aInfo.BidPrice;
               item.BidSize = aInfo.BidSize;
               item.TotalVolume = aInfo.Volume;
 
grid.refresh();
i expected not to have to run the grid refresh with the observable object. But it turns out i still had to do it. or it would not show any changes.
The new code loos like this:
var grid = $("#vmGrid").data("kendoGrid");
var item = tsDataManager.gDataSource.get(id);
 
item.TimeStamp = tStamp;
                item.Close = aInfo.Last;
                item.Price = aInfo.Last;
                item.NetChange = aInfo.Net;
                item.AskPrice = aInfo.AskPrice;
                item.AskSize = aInfo.AskSize;
                item.BidPrice = aInfo.BidPrice;
                item.BidSize = aInfo.BidSize;
                item.TotalVolume = aInfo.Volume;
grid.refresh();
so it's basically the same thing.
I don't get what the advantage is here, especially with the editing of the rows.

Am i using it wrong?

1 Answer, 1 is accepted

Sort by
0
MAGNUS
Top achievements
Rank 1
answered on 03 May 2013, 03:08 PM
see this:
http://stackoverflow.com/questions/15579857/how-to-prevent-kendo-ui-grid-from-rebinding-many-times-when-updating-viewmodels
Tags
Grid
Asked by
Andrew
Top achievements
Rank 1
Answers by
MAGNUS
Top achievements
Rank 1
Share this question
or