[CLOSED] Extending Ext.Net GridPanel

  1. #1

    [CLOSED] Extending Ext.Net GridPanel

    Hi,

    we create custom component, that extend GridPanel. There is a method AddTopBarButtons that create buttons and JS code for them. That javascripts use GridPanel ID propery for access to grid data, when we want to override ID property to access to grid in client script in ASp.Net MVC View, we need to rebuild buttons again, call method AddTopBarButtons. It's is not good decision, but we don't know, what method override before JS markup will be generated. We think that in Ext.Net framework has methods that generate markup. What method can we override before the murkup and JS will be generated, where we can call AddTopBarButtons? Or may be you can show some good example for overriding or extending Ext.Net components?

    Code example:

        public class FvGridPanelEditable : GridPanel
        {
            public new class Builder<TGridPanelEditable, TBuilder> : GridPanel.Builder<TGridPanelEditable, TBuilder>
                where TGridPanelEditable : GridPanel
                where TBuilder : Builder<TGridPanelEditable, TBuilder>
            {
                public Builder(TGridPanelEditable component) : base(component) { }
    
                private bool _isInit;
                private readonly Store _store = new Store();
                private string _action = "";
                private bool _rightAdd;
                private bool _rightDelete;
                private string _gridId = ControllerHelper.CreateUnqiueid();
    
                //В случае, если ID укажет пользователь
                public override TBuilder ID(string id)
                {
                    _gridId = id;
                    return base.ID(id);
                }
    
                /// <summary>
                /// Инициализация компонента
                /// </summary>
                /// <param name="actionName">Имя контроллера на котором лежит ReadData</param>
                /// <param name="userId">Use Method ControllerHelper.GetUserId(Session)</param>
                /// <param name="brRightObject">BrRight object</param>
                public TBuilder FvInit(string actionName, string userId, string brRightObject)
                {
                    _action = actionName;
                    _rightAdd = !BrRights.UserHasPermissionAdd(userId, brRightObject);
                    _rightDelete = !BrRights.UserHasPermissionDelete(userId, brRightObject);
    
                    _isInit = true;
                    return this as TBuilder;
                }
    
                public TBuilder FvGridConfiguration(params ColumnBase[] columns)
                {
                    if (!_isInit)
                        throw new Exception("Сначала необходимо инициализировать гриду вызвав метод FvInit");
    
                    _store.Proxy.Add(new AjaxProxy { Url = UrlHelper.Action(_action) });
                    var proxy = ((AjaxProxy)_store.Proxy.Primary);
                    proxy.Reader.Add(new JsonReader { RootProperty = "data" });
                    var model = new Model();
                    foreach (var columnBase in columns)
                    {
                        if (columnBase is DateColumn)
                            model.Fields.Add(columnBase.DataIndex, ModelFieldType.Date);
                        else
                            model.Fields.Add(columnBase.DataIndex, ModelFieldType.Auto);
                    }
    
                    _store.PageSize = 15;
                    _store.RemoteFilter = true;
                    _store.RemotePaging = true;
                    _store.RemoteSort = true;
                    _store.Model.Add(model);
                    _store.AutoLoad = true;
                    _store.ID = ControllerHelper.CreateUnqiueid();
    
                    ID(_gridId);
    
                    Header(false);
                    Region(Ext.Net.Region.Center);
                    Layout(LayoutType.Fit);
                    EnableColumnHide(false);
    
                    Store(_store);
    
                    //Добавление колонок на гриду
                    foreach (var column in columns)
                        ColumnModel(column);
    
                    Plugins(new GridFilters { MenuFilterText = "Фильтр", });
                    Plugins(new CellEditing { ClicksToEdit = 1 });
                    View(new GridView { StripeRows = true });
                    SelectionModel(new CellSelectionModel());
    
                    BottomBar(new PagingToolbar());
    
                    //Добавление кнопок на гриду
                    AddTopBarButtons();
    
    
                    return this as TBuilder;
                }
    
                private void AddTopBarButtons()
                {
                    var toolBar = new Toolbar();
                    toolBar.Items.Add(new ToolbarFill());
    
                    var btnDelete = new Button
                    {
                        Text = "Удалить",
                        Handler = String.Format("var stor = App.{0}.store; var record = App.{0}.selModel.getSelection(); stor.remove(record)", _gridId),
                        Disabled = _rightDelete,
                        Icon = Ext.Net.Icon.Delete
                    };
    
                    var btnAdd = new Button
                    {
                        Text = "Добавить",
                        Handler = String.Format("var store = App.{0}.store; store.add({{}});", _gridId),
                        Icon = Ext.Net.Icon.Add,
                        Disabled = _rightAdd
                    };
    
                    toolBar.Items.Add(btnAdd);
                    toolBar.Items.Add(btnDelete);
    
                    TopBar(toolBar);
                }
    
                public TBuilder FvAddFilterParameter(string name, string value)
                {
                    _store.Parameters.Add(new StoreParameter(name, value));
                    return this as TBuilder;
                }
            }
    
            public new class Builder : Builder<FvGridPanelEditable, Builder>
            {
                public Builder(FvGridPanelEditable component) : base(component) { }
            }
        }
    Last edited by Daniil; Jun 23, 2015 at 6:42 PM. Reason: [CLOSED]
  2. #2
    Hi Andrey,

    Our best suggestion in your scenario is to avoid using ID at all.

    I think this should work.
    Handler = "var grid = this.up('gridpanel'); ..."

    This post might be helpful also.
    http://forums.ext.net/showthread.php...ll=1#post92621

    There threads regarding extending of Ext.NET controls should be also helpful.
    http://forums.ext.net/showthread.php...ll=1#post78126
    http://forums.ext.net/showthread.php?20420

    Ext.NET book is a great resource as well.
    http://www.onenaught.com/posts/451/b...on-development
    Last edited by Daniil; Jun 09, 2015 at 4:23 PM.
  3. #3

    Can't reject

    HI,

    we can't reject use IDs in JS code, grid ID need to us sending data to server with other form data in AJAX request, this grid only a part of a crazy form. We are premium user, when we purchase lybraries there was promise two copies of this (http://www.onenaught.com/posts/451/b...on-development) book, how can we get access to book in pdf format?

    Can we ask in russian language?
  4. #4

    Extending in MVC

    Your examples to extending ext.net component only for ASP.NET WebForms. We use ASP.NET MVC in our project, hve you some examples to extending MVC labraries.

    In example for WebForms:

    public class FinancialGrid : GridPanel {
    
        public override string InstanceOf
        {       
            get { return "MyApp.FinancialGrid"; }
        }
    
        public override string XType
        {
            get { return "financialgrid"; } 
        }
    
        protected override void OnLoad(EventArgs e)
        {
                 Title = "Simple Grid";
                 Store.Add(BuildStore());
                 ColumnModel.Columns.Add(BuildColumnModel());
                 BottomBar.Add(new PagingToolbar());
                 base.OnLoad(e);
        } 
    }
    developper use method OnLoad to build grid panel, there is right like this method in MVC labraries? Where we can build our grid after user call some tuning methods of our grid in razor markup.
    Last edited by Andrey; Jun 10, 2015 at 5:20 AM.
  5. #5
    We are premium user, when we purchase lybraries there was promise two copies of this (http://www.onenaught.com/posts/451/b...on-development) book, how can we get access to book in pdf format?
    FAQ #10 states:
    Once your purchase of Ext.NET is complete, you will be sent an email with instructions on how to acquire the directly from the Packt website.
    Please check your email inbox, there should be an instruction. If you cannot find, please let me know.

    Can we ask in russian language?
    The idea of our public forums is that most of the community could read it. It means English. Sorry.

    developper use method OnLoad to build grid panel, there is right like this method in MVC labraries?
    I guess a GridPanel's OnLoad should still work in MVC as well...

    Where we can build our grid after user call some tuning methods of our grid in razor markup.
    Sorry, I am not sure I understand the question. Please elaborate.
  6. #6

    Reply

    Sorry, I am not sure I understand the question. Please elaborate.
    When developper use our custom constol (GridPanel), he will call few methods, that will configure our control. After all method been called we need to build control, add buttons, add hidden fields, etc. Right now all custom methods build control right in method wich developper called, for example develloper call methods AddStandartButtons,() there we create two buttons for grid, add and remove row from grid, but whe user call method ChangeRemoveRowButtonText(), we rebuild buttons again, it is for example. Now we ask, ext.net has methods where we can build contol?
  7. #7
    You can try with OnPreRender.
    protected override void OnPreRender(EventArgs e)
    {
        base.OnPreRender(e);
        // Your code
    }
  8. #8

    Thank you

    Ok, we'll try this, thank you!

Similar Threads

  1. [CLOSED] Extending GridPanel + adding Tools
    By exe in forum 2.x Legacy Premium Help
    Replies: 2
    Last Post: Mar 13, 2015, 6:56 AM
  2. [CLOSED] extending textfield
    By metci in forum 2.x Legacy Premium Help
    Replies: 2
    Last Post: Jul 02, 2014, 6:30 AM
  3. [CLOSED] Extending GridPanel
    By jmcantrell in forum 1.x Legacy Premium Help
    Replies: 8
    Last Post: Mar 29, 2012, 1:33 PM
  4. Extending DatePicker
    By onurbozkurt in forum 1.x Help
    Replies: 0
    Last Post: Apr 29, 2009, 8:45 AM

Tags for this Thread

Posting Permissions