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

DataSource.Schema.Parse only fires once

3 Answers 263 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Joshua
Top achievements
Rank 2
Iron
Veteran
Iron
Joshua asked on 13 Nov 2012, 06:34 PM
I have created a data source and I need to parse the data that comes in so it is in the appropriate structure for my grid. I normally do this with parse and all is well.

In this scenario, I need to programatically set the data. When I do this by using the DataSource.data member, then parse is never called.

I have an example in this fiddle: http://jsfiddle.net/grippstick/tjmKm/

If you click switch data you will see the grid populate with the new data, but the parse function is never called.

3 Answers, 1 is accepted

Sort by
0
Brian
Top achievements
Rank 1
answered on 21 Nov 2012, 04:30 PM
I am having the exact same problem I have tried re-reading the data source. This is causing an issue however because for whatever reason it does not yet see the data source as having been updated in any of the events I can tie into.

I am doing the same thing, setting the datasource and then trying to call read to force it to parse again. I've not been able to find a work-around yet.
0
Joshua
Top achievements
Rank 2
Iron
Veteran
Iron
answered on 21 Nov 2012, 04:43 PM
I have been informed that it is by design. I don't know what the design consideration was or think that it is a good design, but these guys know more than me on the topic so I defer to them. :)

For a work around, I reuse the parse function that is already defined and then call it on my data, before I send it in to the data source:


I have a fiddle that demonstrates the solution.
http://jsfiddle.net/grippstick/tjmKm/9/

The pertinent lines are:
//set the data using the parse that is already defined
viewModel.ds.data(
    viewModel.ds.options.schema.parse(newData || []) //just in case thenew data is null
);
0
Brian
Top achievements
Rank 1
answered on 21 Nov 2012, 05:21 PM
I've noticed it's not an issue when completely re-building and re-assigning a datasource to my grid, but I wanted to avoid that at all costs. It's not my preferred solution, but it's elegant enough and it works. Thanks for sharing!
Tags
Data Source
Asked by
Joshua
Top achievements
Rank 2
Iron
Veteran
Iron
Answers by
Brian
Top achievements
Rank 1
Joshua
Top achievements
Rank 2
Iron
Veteran
Iron
Share this question
or