We have been working hard on Ext.NET Mobile and are happy to announce a Beta release is now available. Ext.NET Mobile is an ASP.NET component framework for building Phone and Tablet specific mobile web applications. Read more here

Ext.Net Store.loadData

  1. #1

    Ext.Net Store.loadData

    I tried to make an initialization of Store with some initial data loaded by scripts. Weird is that I coded some server-side scripts but rendered client scripts like the following. It generates errors. Any ideas?
    // server side
                store.AutoLoad = false;
                JsonReader reader = new JsonReader()
                    Root = "data",
                    TotalProperty = "total"
                    new RecordField() { Name = "MetaInfo", Type = RecordFieldType.String });
                    new RecordField() { Name = "TemplateMetaInfo", Type = RecordFieldType.String });
                    new RecordField() { Name = "RootId", Type = RecordFieldType.String });
                var qMappings =
                    from mapping in mappingSource
                    select new
                        MetaInfo = mapping.Key.Key.ToString(),
                        TemplateMetaInfo = mapping.Key.Value.ToString(),
                        RootId = mapping.Value.Id.ToISFormatted()
                TwoStoreResponseData msData = new TwoStoreResponseData();
                msData.Total = qMappings.Count();
                msData.Data = JSON.Serialize(qMappings.ToList());
                store.LoadData(msData.ToString(), true);
    While I captured client side scripts by viewing the page source

    ctl00_C_dsTypeTemplateMappings.loadData("{data:[{\"MetaInfo\":\"Appointment\",\"TemplateMetaInfo\":\"FormTemplate\",\"RootId\":\"7060898AA5C7445287A055294570DA76\"},{\"MetaInfo\":\"Article\",\"TemplateMetaInfo\":\"FormTemplate\",\"RootId\":\"7060898AA5C7445287A055294570DA76\"},{\"MetaInfo\":\"BitFile\",\"TemplateMetaInfo\":\"FormTemplate\",\"RootId\":\"7060898AA5C7445287A055294570DA76\"},{\"MetaInfo\":\"Customer\",\"TemplateMetaInfo\":\"FormTemplate\",\"RootId\":\"7060898AA5C7445287A055294570DA76\"},{\"MetaInfo\":\"HtmlPeriod\",\"TemplateMetaInfo\":\"FormTemplate\",\"RootId\":\"7060898AA5C7445287A055294570DA76\"},{\"MetaInfo\":\"Person\",\"TemplateMetaInfo\":\"FormTemplate\",\"RootId\":\"7060898AA5C7445287A055294570DA76\"},{\"MetaInfo\":\"Product\",\"TemplateMetaInfo\":\"FormTemplate\",\"RootId\":\"7060898AA5C7445287A055294570DA76\"},{\"MetaInfo\":\"Project\",\"TemplateMetaInfo\":\"FormTemplate\",\"RootId\":\"7060898AA5C7445287A055294570DA76\"}], total: 8}",true);
    Isn't that loadData shoud be input with a object parameter instead of string? I placed an Ext.decode() to string then rendered a pretty right result.
  2. #2

    RE: Ext.Net Store.loadData

    Hello, cleve!

    I think I can help if you let me see at the rest part of you code to reproduce the errors you mentioned.
    Daniil Veriga
    Developer & Support Expert
  3. #3

    RE: Ext.Net Store.loadData

    Hi again.This code looks a little bit strange.

     TwoStoreResponseData msData = new TwoStoreResponseData();
    msData.Total = qMappings.Count();
    msData.Data = JSON.Serialize(qMappings.ToList());
    store.LoadData(msData.ToString(), true);
    Try to replace this by the following code.

    store.DataSource = qMappings.ToList();
    Did it help you?

    P.S. It seems the Help forum is more appropriate for this topic than the Bugs forum.

    Daniil Veriga
    Developer & Support Expert
  4. #4

    RE: Ext.Net Store.loadData

    Hi Daniil,

    Thanks for your reply. The code you appended works fine if I erase the reader settings (Root and TotalProperty). I think I have serval points to add on this post for the reason why I think it is more likely a bug.

    The class definition which you can find as "TwoStoreReponseData" is a sub-class derived from "StoreResponseData" whose "ToString()" function produces a Json format with root name "data" and "total" property. StoreReponseData is a usful class I use in the project to generate Json-based MVC action results (transmitting a zipped store data).

    That's why I want to generalize this format to let the rest of my store definitions confine with this usage convention.

    - On previous version (0.8.2) afore server-side script works fine and the rendered JS scripts are correctly mapped to store.loadData(jsonObject, isAppended). But 1.0 version renders another format which is store.loadData(jsonString, isAppended). To translate jsonString to jsonObject, I think a wrap "Ext.decode()" is required. If not, reader's getRoot function will generate an error. That's the one I mentioned at the original post saying some errors occurred.

    - At 1.0 version, StoreReponseData.ToString() changed the totalProperty name which is from "totalCount" to "total". Other implementation of it remains the same. So when I changed the way I initialize the store with the following:

                // Your solution
                // store.DataSource = qMappings.ToList();
                // store.DataBind();
                store.AutoLoad = true;
    It works fine! That means the Json format is still accepted by the store and reader definition.

    - Furtherly when I double check the way DataBind or SetDataFromJson, I found they use different mapping to client-side JS script render, comparing with LoadData. They both use Ext.data.PagingMemoryProxy to create a Json block proxy for reader to read.

    So in conclusion, StoreReponseData is producing a correct Json string and Store reader still accept the way to read the string if reader and root are correctly specified. Problematic is LoadData, which is at server-side should render a client-side loadData function without quoting the string object put to server-side function call.

  5. #5

    RE: Ext.Net Store.loadData

    Hello, cleve!

    Maybe you are right, maybe not:) I think the creators of this toolkit can answer on this question - it's a bug or not? Perhaps, they have already answered on it because this topic is moved to Help from Bug forum:)
    Daniil Veriga
    Developer & Support Expert

Similar Threads

  1. [CLOSED] [2.0] Razor and Store LoadData
    By Timothy in forum 2.x Premium Help
    Replies: 8
    Last Post: Jun 28, 2012, 6:45 PM
  2. Store.loadData()
    By glenh in forum 1.x Help
    Replies: 2
    Last Post: Dec 05, 2011, 3:34 AM
  3. About Ext.Net Store.loadData
    By caoit in forum 1.x Help
    Replies: 0
    Last Post: Apr 26, 2011, 2:41 AM
  4. [1.0] Store.LoadData vs DataBind
    By Kam in forum 1.x Help
    Replies: 1
    Last Post: Apr 19, 2011, 11:00 AM
  5. [CLOSED] Store loadData() wierd error.
    By capecod in forum 1.x Premium Help
    Replies: 9
    Last Post: Nov 10, 2010, 8:46 AM

Posting Permissions

Subscribe now to get the latest Ext.NET happenings in our newsletter.