Updating GridPanel Store

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Updating GridPanel Store

    I had a hard time figuring out how to update store in 7.2 in controller.
    Posting my solution. Hopefully it will save time for someone.

    List<Company> GetCompanies()
            {
                return new List<Company>
                {
                    new Company {id = 1, name = "3m Co" },
                    new Company {id = 2, name = "Alcoa Inc" },
                    new Company {id = 3, name = "Altria Group Inc" },
                    new Company {id = 4, name = "American Express Company" },
                };
            }
    
    public void OnGet()
            {
                this.GridData ??= GetCompanies().ToList<object>();
            }
    
    public IActionResult OnPostButtonSave_Click(int id, string name, string window)
            {
                List<Company> companies = GetCompanies();
                companies.FirstOrDefault(c => c.id == id).name = name;
    
                this.GetCmp<Window>(window).Close();
                var gp = this.GetCmp<GridPanel>("gpOne");
                gp.Store = new Store
                {
                    Data = companies.ToList<object>(),
                    Fields = new List<DataField>
                    {
                        new NumberDataField { Name = "id" },
                        new DataField{ Name = "name" },
                    }
                };
                return this.Direct();
            }
    Last edited by VADIM; Apr 04, 2021 at 4:11 PM. Reason: Update

Similar Threads

  1. [CLOSED] Updating Store from Selected Record in GridPanel
    By Argenta in forum 3.x Legacy Premium Help
    Replies: 4
    Last Post: Mar 01, 2016, 4:24 PM
  2. [CLOSED] Auto Updating Store Custom Component
    By vgvallee in forum 2.x Legacy Premium Help
    Replies: 4
    Last Post: Oct 22, 2013, 11:44 PM
  3. Help! Updating Store with complex data...
    By maxiom in forum 1.x Help
    Replies: 1
    Last Post: Aug 06, 2012, 8:49 AM
  4. [CLOSED] Store Filter Not Updating Grid
    By peter.campbell in forum 1.x Legacy Premium Help
    Replies: 6
    Last Post: May 23, 2012, 3:47 PM
  5. Updating GridPanel Store in AjaxEvent
    By niceguymattx in forum 1.x Help
    Replies: 2
    Last Post: Mar 10, 2010, 5:36 AM

Posting Permissions