RESTful Store question

  1. #1

    RESTful Store question

    Hi Guys,

    I have a question about RESTful Store. Here is my code.

        <script>
            var onWrite = function(store, operation) {
                var record = operation.getRecords()[0],
                    name = Ext.String.capitalize(operation.action),
                    verb;
    
                if (name == 'Destroy') {
                    record = operation.records[0];
                    verb = 'Destroyed';
                } else {
                    verb = name + 'd';
                }
                Ext.net.Notification.show({ title: name, html: Ext.String.format("abc") });
            };
    
            var StockItemNameSelect = function(combo, record, index) {
                var val = combo.getValue();
                var g = Ext.getCmp('myGrid');
                //var sm = g.getSelectionModel();
                //var rec = sm.selection.record;
    
                var rec = g.getSelectionModel().getSelection()[0];
                rec.set('StockItemName', val);
                alert(rec.get('StockItemName'));
                //rec.set('common', 'whatever');
            };
        </script>
    
     @(X.Store()
              .ID("StockItemStore")
              .Model(
                  Html.X().Model()
                      .Fields(
                          X.ModelField().Name("text").Mapping("Text").Type(ModelFieldType.String),
                          new ModelField("Stockcode", ModelFieldType.String),
                          new ModelField("Name1", ModelFieldType.String),
                          new ModelField("Name2", ModelFieldType.String),
                          new ModelField("Catid", ModelFieldType.Int),
                          new ModelField("Unitid", ModelFieldType.Int),
                          new ModelField("UnitType", ModelFieldType.String),
                //new ModelField("Unit", ModelFieldType.String),
                          new ModelField("Supplierid", ModelFieldType.Int),
                          new ModelField("Price", ModelFieldType.Float),
                          new ModelField("Isenable", ModelFieldType.Int),
                          new ModelField("Leastinventory", ModelFieldType.Float)
                //,
                //new ModelField("CategoryName1", ModelFieldType.String),
                //new ModelField("CategoryName2", ModelFieldType.String)
    
                      )
              )
              .Proxy(X.AjaxProxy()
                  .Url(Url.Action("GetStockItemList"))
                  .Reader(X.JsonReader().Root("data"))
              )
              )
    
        @(
    
     X.GridPanel()
                .ID("myGrid")
        .Height(300)
        .Store(
            Html.X().StoreForModel().Control(s =>
            {
                s.AutoSync = true;
                s.Parameters.Add(new StoreParameter("id", "Ext.decode(Ext.util.Cookies.get('ItemCode'))", ParameterMode.Raw));
                s.Proxy.Add(
                    new RestProxy
                    {
                        AppendAction = false,
                        Reader =
                        {
                            new JsonReader
                            {
                                Root = "data",
                                MessageProperty = "message"
                            }
                        },
                        API =
                        {
                            Read = Url.Action("Read"),
                            Update = Url.Action("Update"),
                            Create = Url.Action("Create"),
                            Destroy = Url.Action("Destroy")
                        },
                        Writer =
                        {
                            new JsonWriter
                            {
                                AllowSingle = true
                            }
                        }
                    }
                    );
                s.Listeners.Write.Fn = "onWrite";
            })
        )
        .ColumnModel(
            X.NumberColumn()
                .Text("数量")
                .DataIndex("Qty")
                .Flex(1)
                .Editor(
                    Html.X().TextField().AllowBlank(false)
                )
                .Width(200),
    
            X.Column()
                .Text("原料")
                .DataIndex("StockItemName")
                .Flex(1)
                .Editor(
                    X.ComboBox()
                        //.TriggerAction(TriggerAction.All)
                        .StoreID("StockItemStore")
                        .ValueField("Stockcode")
                        .DisplayField("Name2")
                        .Listeners(ls =>
                        {
                            ls.Select.Fn = "StockItemNameSelect";
    
                        })
                )
                .Width(200)
        )
        .TopBar(
            Html.X().Toolbar()
                .Items(
                    Html.X().Button()
                        .Text("Add")
                        .Icon(Icon.Add)
                        .Handler("this.up('grid').store.insert(0, new Matching());this.up('grid').editingPlugin.startEdit(0, 0);"),
    
                    Html.X().Button()
                        .ItemID("btnRemove")
                        .Text("Delete")
                        .Icon(Icon.Exclamation)
                        .Handler("this.up('grid').deleteSelected();")
                )
        )
        .Plugins(
            Html.X().RowEditing()
                .Listeners(l =>
                {
                    l.CancelEdit.Handler = "if(e.record.phantom){e.store.remove(e.record);}";
                })
        )
              )
    Strange thing is when I select a value in combox, the update function in server-side will be executed. Why not when I click the 'Update' button?

    Thanks
    Attached Thumbnails Click image for larger version. 

Name:	20150818221730.png 
Views:	34 
Size:	8.9 KB 
ID:	24153  
  2. #2
    Sorry for my bad code, please close the case.
  3. #3
    Hi @qch2007qch,

    Welcome to the Ext.NET forums!

    Sharing a solution might help others in the future. It doesn't mean that we require you to share a solution, though:)

Similar Threads

  1. Restful Store and SubmitEmptyValue
    By Dimitris in forum 1.x Help
    Replies: 1
    Last Post: May 27, 2012, 6:41 PM
  2. Replies: 3
    Last Post: Jan 19, 2012, 9:56 AM
  3. [CLOSED] [1.0] Restful Store API
    By Timothy in forum 1.x Legacy Premium Help
    Replies: 7
    Last Post: Oct 22, 2010, 7:13 AM
  4. [CLOSED] [1.0] Store Restful
    By Timothy in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Oct 04, 2010, 4:50 PM
  5. [CLOSED] Restful Store Question
    By Timothy in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Mar 20, 2010, 2:23 PM

Tags for this Thread

Posting Permissions