Jun 09, 2015, 6:12 AM
[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:
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]