DataSource.Schema.Parse only fires once

4 posts, 0 answers
  1. Joshua
    Joshua avatar
    69 posts
    Member since:
    May 2012

    Posted 13 Nov 2012 Link to this post

    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.
  2. Brian
    Brian avatar
    17 posts
    Member since:
    Nov 2012

    Posted 21 Nov 2012 Link to this post

    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.
  3. Joshua
    Joshua avatar
    69 posts
    Member since:
    May 2012

    Posted 21 Nov 2012 Link to this post

    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
    );
  4. Brian
    Brian avatar
    17 posts
    Member since:
    Nov 2012

    Posted 21 Nov 2012 Link to this post

    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!
Back to Top