FineUI 官方论坛
标题:
要分組和鎖定列很簡單,主要是ExtJS是支持的。只要糾正/...
[打印本页]
作者:
Herry
时间:
2014-4-25 15:34
标题:
要分組和鎖定列很簡單,主要是ExtJS是支持的。只要糾正/...
要分組和鎖定列很簡單,主要是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);
}
作者:
bluer
时间:
2014-4-25 17:30
很好。。强大。
作者:
huifeideyu888
时间:
2014-4-26 16:51
改哪个js,请您说详细下好吗
作者:
~~疯狂~~
时间:
2014-5-5 11:27
您好!我用您的代码测试了一下,没有效果,请问能否给一个示例。非常感谢!
作者:
~~疯狂~~
时间:
2014-5-5 15:06
使用官网示例:FineUI.Examples/grid/grid.aspx 结合您的代码修改如下,运行无效。
aspx代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="grid.aspx.cs" Inherits="FineUI.Examples.grid.grid" %>
<!DOCTYPE html>
<html>
<head runat="server">
<title></title>
<link href="../css/main.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form id="form1" runat="server">
<x:PageManager ID="PageManager1" runat="server" />
<x:Grid ID="Grid1" ShowBorder="true" ShowHeader="true" Title="表格" Width="400px" runat="server"
DataKeyNames="Guid">
<Columns>
<x:TemplateField ColumnID="f1" Width="60px">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Container.DataItemIndex + 1 %>'></asp:Label>
</ItemTemplate>
</x:TemplateField>
<x:BoundField ColumnID="f2" Width="100px" DataField="Name" DataFormatString="{0}" HeaderText="姓名" />
<x:TemplateField Width="60px" HeaderText="性别">
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# GetGender(Eval("Gender")) %>'></asp:Label>
</ItemTemplate>
</x:TemplateField>
<x:BoundField Width="60px" DataField="EntranceYear" HeaderText="入学年份" />
<x:CheckBoxField Width="60px" RenderAsStaticField="true" DataField="AtSchool" HeaderText="是否在校" />
<x:HyperLinkField HeaderText="所学专业" DataToolTipField="Major" DataTextField="Major"
DataTextFormatString="{0}" DataNavigateUrlFields="Major" DataNavigateUrlFormatString="http://gsa.ustc.edu.cn/search?q={0}"
DataNavigateUrlFieldsEncode="true" Target="_blank" ExpandUnusedSpace="True" />
<x:ImageField Width="60px" DataImageUrlField="Group" DataImageUrlFormatString="~/images/16/{0}.png"
HeaderText="分组">
</x:ImageField>
<x:BoundField Width="100px" DataField="LogTime" DataFormatString="{0:yy-MM-dd}" HeaderText="注册日期" />
</Columns>
</x:Grid>
<br />
<br />
</form>
</body>
</html>
复制代码
cs代码:
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Text;
using System.IO;
namespace FineUI.Examples.grid
{
public partial class grid : PageBase
{
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);
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GridHelp.GridFieldLock(Grid1, new string[] { "f1", "f2" });
//GridHelp.GridFieldGroup(Grid1, "f1", "fx", true);
BindGrid();
}
}
#region BindGrid
private void BindGrid()
{
DataTable table = GetDataTable();
Grid1.DataSource = table;
Grid1.DataBind();
}
#endregion
}
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)));
}
}
}
复制代码
作者:
~~疯狂~~
时间:
2014-5-5 15:07
~~疯狂~~ 发表于 2014-5-5 15:06
使用官网示例:FineUI.Examples/grid/grid.aspx 结合您的代码修改如下,运行无效。
运行没有报错,但是不会锁定列。
作者:
~~疯狂~~
时间:
2014-5-6 09:06
请问您使用的是4的版本还是3的版本?
作者:
Herry
时间:
2014-5-7 22:32
本帖最后由 Herry 于 2014-5-7 22:36 编辑
4版,不修改FineUI本身,要用protected override void Render(System.Web.UI.HtmlTextWriter writer)调整,protected override void Render(System.Web.UI.HtmlTextWriter writer) 可以放在BasePage里面。web.config中FineUI的Debug设置为false.
作者:
csalx
时间:
2014-5-9 19:06
严重关注,有人试验成功没?分享下经验,楼主说的没太看明白
作者:
水木山人
时间:
2014-5-9 19:26
make a mark!
作者:
yygy
时间:
2014-5-18 10:07
真的可以锁定列,问题是列的标题会改变,怎样更正?
[attach]5285[/attach]
[attach]5286[/attach]
作者:
mfz
时间:
2014-7-14 17:48
收藏下 日后方便查看
作者:
txw999
时间:
2014-7-27 14:52
在企业管理软件中,这的功能基本是必段的,收藏备用
作者:
lqf20908
时间:
2014-8-26 07:59
收藏备用
欢迎光临 FineUI 官方论坛 (https://fineui.com/bbs/)
Powered by Discuz! X3.4