How to assign store.

  1. #1

    How to assign store.

    Hi,

    I am trying to build a grid panel that will have a dynamic schema. The content and schema of the grid will change based on query from user. I am having problems loading the fields from the new query, which I believe is caused by me not updating the store properly. The relevant code I am using is as follows:

    //Note: resultTable is of DataTable type

    //Inside View
     X.Panel()
                .ID("CenterNorth")
                .Layout(LayoutType.Border)
                // .Frame(true)
                .Title("Data")
                    .Items(
                    X.GridPanel() //Main Content 
                    .ID("GridPanel1")
                    .Region(Region.Center)
                    .Frame(true)
                    .Store(
                        X.Store()
                        .Model(Model.resultModel)
                        .Proxy(X.AjaxProxy()
                                        .Url(@Url.Action("GetFullData"))
                                        .Reader(X.JsonReader().Root("data"))
                                    )
                    )
    .
    .//A form fields for the query
    .
    //Button to submit data
                            X.Button()
                            .Text("Submit")
                            .Handler(@"#{DirectMethods}.RunQuery(App.NameSelect.getValue());
                                          App.GridPanel1.getStore().sync()")
    //Inside Controller
        [DirectMethod]
            public ActionResult RunQuery(string qry_params)
            {
                db.SetModelAndData(string.Format("Select * from {0}",qry_params.Trim(new char[]{'"','[',']','\\'})));
    
    
                this.GetCmp<GridPanel>("GridPanel1").Store.Remove(this.GetCmp<GridPanel>("GridPanel1").GetStore());
                Store xStore = new Store();
    
                xStore.DataSource = db.Serialize().ToList(); //Convert to Json format
                xStore.Model.Add(db.resultModel);
                xStore.DataBind();
    
                this.GetCmp<GridPanel>("GridPanel1").Store.Add(xStore);
    
                this.GetCmp<GridPanel>("GridPanel1").RemoveAllColumns();
                for (int i = 0; i < db.resultTable.Columns.Count; i++)
                {
                    this.GetCmp<GridPanel>("GridPanel1")
                        .AddColumn(
                        new Column
                        {
                            DataIndex = db.resultTable.Columns[i].ColumnName,
                            Text = db.resultTable.Columns[i].ColumnName
                        });
                }
    
                return this.Direct();
            }
    
            public ActionResult GetFullData()
            {
                return this.Store(db.Serialize().ToList(), db.resultModel);
            }
    When I run the above code with the submit button, the table columns get updated according to the query, however, the data does not load.
    I am quite new to .NET framework as well as EXT.Net, hence any tips or advice is appreciated.

    Massoud
    Last edited by massman07; Jul 10, 2014 at 5:01 PM.
  2. #2
    Hi @massman07,

    Welcome to the Ext.NET forums!

    Please post a response of the GetFullData when it doesn't work.
  3. #3
    Thanks @Daniil for the quick reply,

    For some reason when I click the RunQuery button, GetFullData does not run, according to browser console. When I browse to the action, I get:

    {
        "data": [{
            "name": "spt_fallback_db",
            "object_id": 117575457,
            "principal_id": null,
            "schema_id": 1,
            "parent_object_id": 0,
            "type": "U ",
            "type_desc": "USER_TABLE",
            "create_date": "2003-04-08T09:18:01.557",
            "modify_date": "2008-07-09T16:54:05.24",
            "is_ms_shipped": true,
            "is_published": false,
            "is_schema_published": false,
            "lob_data_space_id": 0,
            "filestream_data_space_id": null,
            "max_column_id_used": 8,
            "lock_on_bulk_load": false,
            "uses_ansi_nulls": true,
            "is_replicated": false,
            "has_replication_filter": false,
            "is_merge_published": false,
            "is_sync_tran_subscribed": false,
            "has_unchecked_assembly_data": false,
            "text_in_row_limit": 0,
            "large_value_types_out_of_row": false,
            "is_tracked_by_cdc": false,
            "lock_escalation": 0,
            "lock_escalation_desc": "TABLE"
        }, {
            "name": "spt_fallback_dev",
            "object_id": 133575514,
            "principal_id": null,
            "schema_id": 1,
            "parent_object_id": 0,
            "type": "U ",
            "type_desc": "USER_TABLE",
            "create_date": "2003-04-08T09:18:02.87",
            "modify_date": "2008-07-09T16:54:05.24",
            "is_ms_shipped": true,
            "is_published": false,
            "is_schema_published": false,
            "lob_data_space_id": 0,
            "filestream_data_space_id": null,
            "max_column_id_used": 10,
            "lock_on_bulk_load": false,
            "uses_ansi_nulls": true,
            "is_replicated": false,
            "has_replication_filter": false,
            "is_merge_published": false,
            "is_sync_tran_subscribed": false,
            "has_unchecked_assembly_data": false,
            "text_in_row_limit": 0,
            "large_value_types_out_of_row": false,
            "is_tracked_by_cdc": false,
            "lock_escalation": 0,
            "lock_escalation_desc": "TABLE"
        }, {
            "name": "spt_fallback_usg",
            "object_id": 149575571,
            "principal_id": null,
            "schema_id": 1,
            "parent_object_id": 0,
            "type": "U ",
            "type_desc": "USER_TABLE",
            "create_date": "2003-04-08T09:18:04.18",
            "modify_date": "2008-07-09T16:54:05.253",
            "is_ms_shipped": true,
            "is_published": false,
            "is_schema_published": false,
            "lob_data_space_id": 0,
            "filestream_data_space_id": null,
            "max_column_id_used": 9,
            "lock_on_bulk_load": false,
            "uses_ansi_nulls": true,
            "is_replicated": false,
            "has_replication_filter": false,
            "is_merge_published": false,
            "is_sync_tran_subscribed": false,
            "has_unchecked_assembly_data": false,
            "text_in_row_limit": 0,
            "large_value_types_out_of_row": false,
            "is_tracked_by_cdc": false,
            "lock_escalation": 0,
            "lock_escalation_desc": "TABLE"
        }, {
            "name": "spt_monitor",
            "object_id": 1115151018,
            "principal_id": null,
            "schema_id": 1,
            "parent_object_id": 0,
            "type": "U ",
            "type_desc": "USER_TABLE",
            "create_date": "2008-07-09T16:46:12.767",
            "modify_date": "2008-07-09T16:54:05.253",
            "is_ms_shipped": true,
            "is_published": false,
            "is_schema_published": false,
            "lob_data_space_id": 0,
            "filestream_data_space_id": null,
            "max_column_id_used": 11,
            "lock_on_bulk_load": false,
            "uses_ansi_nulls": true,
            "is_replicated": false,
            "has_replication_filter": false,
            "is_merge_published": false,
            "is_sync_tran_subscribed": false,
            "has_unchecked_assembly_data": false,
            "text_in_row_limit": 0,
            "large_value_types_out_of_row": false,
            "is_tracked_by_cdc": false,
            "lock_escalation": 0,
            "lock_escalation_desc": "TABLE"
        }, {
            "name": "spt_values",
            "object_id": 1131151075,
            "principal_id": null,
            "schema_id": 1,
            "parent_object_id": 0,
            "type": "U ",
            "type_desc": "USER_TABLE",
            "create_date": "2008-07-09T16:46:13.047",
            "modify_date": "2014-06-04T08:48:49.053",
            "is_ms_shipped": true,
            "is_published": false,
            "is_schema_published": false,
            "lob_data_space_id": 0,
            "filestream_data_space_id": null,
            "max_column_id_used": 6,
            "lock_on_bulk_load": false,
            "uses_ansi_nulls": true,
            "is_replicated": false,
            "has_replication_filter": false,
            "is_merge_published": false,
            "is_sync_tran_subscribed": false,
            "has_unchecked_assembly_data": false,
            "text_in_row_limit": 0,
            "large_value_types_out_of_row": false,
            "is_tracked_by_cdc": false,
            "lock_escalation": 0,
            "lock_escalation_desc": "TABLE"
        }],
        "total": 0
    }
    But this still contains the data from the initialized query I set at compile time.
    Last edited by Daniil; Jul 11, 2014 at 4:18 PM. Reason: Please use [CODE] tags
  4. #4
    For some reason when I click the RunQuery button, GetFullData does not run, according to browser console.
    Could you, please, clarify why you expect it should be called?

    Because of this code?
    this.GetCmp<GridPanel>("GridPanel1").Store.Remove(this.GetCmp<GridPanel>("GridPanel1").GetStore());
    ...
    
    this.GetCmp<GridPanel>("GridPanel1").Store.Add(xStore);
    It is not going to work with X.GetCmp<>(). Here are some details why.
    http://forums.ext.net/showthread.php...l=1#post176681

    You can reload the Store by this code. Please note that reloading means re-triggering a GetFullData request.
  5. #5
    @Daniil

    The idea behind the code snippet you mentioned is to bind the data to the store for grid-panel manually, which I originally thought is why the grid will not load the data after RunQuery() method is called. But now I'm starting to think the problem may be something else.

    When RunQuery is called,
    db.SetModelAndData(string.Format("Select * from {0}",qry_params.Trim(new char[]{'"','[',']','\\'})
    sets the content for the datatable and ExtModel which are variables inside the db class.

    This ajax call for the grid panel gets its data from GetFullData.
    Proxy(X.AjaxProxy()
                  .Url(@Url.Action("GetFullData"))
                  .Reader(X.JsonReader().Root("data"))
              )
    So when the RunQuery is called by this:

    X.Button()
    .Text("Submit")
    .Handler(@"#{DirectMethods}.RunQuery(App.NameSelect.getValue());
                  App.GridPanel1.getStore().load()")
    I expect the new values for the db class variables to be returned by GetFullData (I'm not sure if this is actually how it works) to GridPanel store. But somehow, the values shown in the response, are the old ones. Also, the columns on the grid change according to the query, but the data does not.

    I apologize in advance if I'm causing any confusion.
  6. #6
    Also, the columns on the grid change according to the query, but the data does not.
    Well, I have tried to explain why and, I am afraid, I don't have better words.

    But I have an idea. If you need to change everything, the GridPanel's Columns and Store, then I would suggest to create a new GridPanel entirely and render it.
    http://mvc.ext.net/#/GridPanel_Array...vent_Creation/

    If you do that with the same GridPanel's ID, a new GridPanel should replace the new one.
  7. #7
    Thanks again,

    What you suggested makes sense. It is actually loading the data properly. I am still having the issue with the data being old. However, I've discovered this is actually not a EXT.NET problem but rather an MVC.NET problem. I have the datatables as properties inside the db class which I have instantiated inside the controller. What I did not realize until now is that each action inside the controller will reference its own instance of the class and ignore any changes made to it by other actions. I suppose this is an entirely different issue on its own and can be discussed elsewhere.
  8. #8
    I am glad to here that you were able to find out the reason. Thanks for sharing.

Similar Threads

  1. [CLOSED] Error when assign datasource to store in user control
    By redi in forum 2.x Legacy Premium Help
    Replies: 8
    Last Post: Dec 18, 2013, 1:59 AM
  2. Replies: 1
    Last Post: Jun 18, 2013, 3:56 PM
  3. [CLOSED] store total record count assign (e.Total)
    By majestic in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Jan 23, 2012, 12:13 PM
  4. [CLOSED] assign collection to store on the client
    By LeeTheGreek in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: May 23, 2010, 6:46 PM
  5. [CLOSED] [1.0]Assign an iframe ID?
    By vali1993 in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Apr 19, 2010, 5:50 PM

Tags for this Thread

Posting Permissions