要分組和鎖定列很簡單,主要是ExtJS是支持的。只要糾正/替換一下產生的JS就可以了。
1.不修改FineUI空間本身,方便日後升級;
2.只找下JS做修正,簡單容易。
先增加幾個函數:- public static class GridHelp
- {
- /// <summary>
- /// Grid功能重置
- /// </summary>
- public static Dictionary<string, string> GridReset = new Dictionary<string, string>();
- /// <summary>
- /// Grid欄位鎖定(類似Excel列凍結)
- /// </summary>
- /// <param name="g">表格</param>
- /// <param name="ColumnID">唯一標識</param>
- public static void GridFieldLock(FineUI.Grid g, String[] ColumnIDs)
- {
- String GridFieldLockMark = "{1C1A60AC-9E4B-4688-991F-BE95290BD1E9}";
- String GridFieldUnLockMark = "{1D1CE2BE-C0E1-4DFB-A3AA-FF30A8DE73A5}";
- foreach (GridColumn gc in g.Columns)
- {
- g.FindColumn(gc.ColumnID).HeaderText += GridFieldUnLockMark;
- }
- foreach (String gid in ColumnIDs)
- {
- g.FindColumn(gid).HeaderText = g.FindColumn(gid).HeaderText.Replace(GridFieldUnLockMark, "");
- g.FindColumn(gid).HeaderText += GridFieldLockMark;
- }
- GridReset.Add(GridFieldLockMark + """, "",locked:true,lockable:false");
- GridReset.Add(GridFieldUnLockMark + """, "",lockable:false");
- }
- /// <summary>
- /// Grid設置分組
- /// </summary>
- /// <param name="g">表格</param>
- /// <param name="FirstColumnID">第一列ColumnI</param>
- /// <param name="GroupColumnID">需要分組列的ColumnI</param>
- /// <param name="Collapsed">是否不展開</param>
- public static void GridFieldGroup(FineUI.Grid g, String FirstColumnID, String GroupColumnID, Boolean Collapsed)
- {
- string GridMark = "features:[{ftype:'grouping',groupHeaderTpl:'X1',hideGroupedHeader:true,enableGroupingMenu:false,startCollapsed:X2}],";
- GridMark = GridMark.Replace("X1", "{name}").Replace("X2", Collapsed ? "true" : "false");
- GridReset.Add("id:"" + g.ClientID + "",", "id:"" + g.ClientID + ""," + GridMark);
- GridMark = ("Ext.create('Ext.data.ArrayStore',{fields:[{name:"X"}").Replace("X", FirstColumnID);
- GridReset.Add(GridMark, GridMark.Replace("fields:", ("groupField:'X',fields:").Replace("X", GroupColumnID)));
- }
- }
复制代码 然後重寫WebFrom頁面事件:
- protected override void Render(System.Web.UI.HtmlTextWriter writer)
- {
- StringWriter sw = new StringWriter();
- base.Render(new System.Web.UI.HtmlTextWriter(sw));
- String html = sw.ToString();
- if (GridHelp.GridReset.Count > 0)
- {
- foreach (KeyValuePair<string, string> dict in GridHelp.GridReset)
- {
- html = html.Replace(dict.Key, dict.Value);
- }
- }
- writer.Write(html);
- }
复制代码 OK,接下來直接使用:
if (!IsPostBack)
{
GridHelp.GridFieldLock(Grid1, new string[] { "f1", "f2", "f3", "f4" });
GridHelp.GridFieldGroup(Grid1, "f1", "fx", true);
}
|