列表API
通过列表自定义代码可实现列表列的显示、隐藏、增加、单元格显示、过滤条件修改及功能按钮逻辑编写等功能。
系统按钮编码
| 按钮编码 | 描述 |
|---|---|
Create |
新增 |
Import |
导入 |
Export |
导出 |
Remove |
删除 |
Print |
打印 |
列表 API 说明
public class D00018BFlow_ListViewController : H3.SmartForm.ListViewController
{
public D00018BFlow_ListViewController(H3.SmartForm.ListViewRequest request) : base(request)
{
}
protected override void OnInit(H3.SmartForm.LoadListViewResponse response)
{
base.OnInit(response);
}
protected override void OnLoad(H3.SmartForm.LoadListViewResponse response)
{
base.OnLoad(response);
}
protected override void OnSubmit(string actionName, H3.SmartForm.ListViewPostValue postValue, H3.SmartForm.SubmitListViewResponse response)
{
base.OnSubmit(actionName, postValue, response);
}
}
接口列表
构造方法
功能描述
构造方法用于实例化对象。
接口定义
public ListViewController(H3.SmartForm.ListViewRequest request) : base(request);
参数
| 参数名称 | 是否必填 | 类型 | 描述 |
|---|---|---|---|
| request | 是 | H3.SmartForm.ListViewRequest |
上下文环境 |
返回值
无返回值。
示例
public class D00018BFlow_ListViewController : H3.SmartForm.ListViewController
{
private readonly TestInstance = null;
public D00018BFlow_ListViewController(H3.SmartForm.ListViewRequest request) : base(request)
{
TestInstance = new TestInstance(request.Engine);
}
protected override void OnInit(H3.SmartForm.LoadListViewResponse response)
{
base.OnInit(response);
}
protected override void OnLoad(H3.SmartForm.LoadListViewResponse response)
{
base.OnLoad(response);
}
protected override void OnSubmit(string actionName, H3.SmartForm.ListViewPostValue postValue, H3.SmartForm.SubmitListViewResponse response)
{
base.OnSubmit(actionName, postValue, response);
}
}
加载列表设置事件
功能描述
OnInit 执行时,列表设置信息已添加到 LoadListViewResponse 中。可通过对 LoadListViewResponse 操作实现以下功能:
- 添加筛选条件
- 调整按钮
- 设置默认排序字段
- 添加列
- 修改列名称
- 隐藏列
平台默认按钮如下:
| 按钮编码 | 按钮名称 | 按钮图标 |
|---|---|---|
Create |
新增 | fa-plus |
Import |
导入 | fa-download |
Export |
导出 | fa-upload |
Remove |
删除 | fa-times |
接口定义
protected override void OnInit(H3.SmartForm.LoadListViewResponse response)
参数
| 参数名称 | 是否必填 | 类型 | 描述 |
|---|---|---|---|
response |
是 | H3.SmartForm.LoadListViewResponse |
返回值 |
返回值
无返回值,通过 response 返回数据。
示例
protected override void OnInit(H3.SmartForm.LoadListViewResponse response)
{
// 添加查询条件示例
H3.Data.Filter.Filter filter = new H3.Data.Filter.Filter();
H3.Data.Filter.And andMatcher = new H3.Data.Filter.And();
andMatcher.Add(new H3.Data.Filter.ItemMatcher("控件编码", H3.Data.ComparisonOperatorType.Equal, "Value"));
filter.Matcher = andMatcher;
this.Request.Filter = filter;
// 删除按钮示例
response.Actions.Remove("Import");
// 设置默认排序字段示例
response.SortBy = "SeqNo";
response.SortDirection = H3.Data.Filter.SortDirection.Ascending;
// 添加列示例
Dictionary<string, H3.SmartForm.ListViewColumn> columns = new Dictionary<string, H3.SmartForm.ListViewColumn>();
foreach(string key in response.Columns.Keys)
{
columns.Add(key, response.Columns[key]);
if(key == "SeqNo")
{
string myNewCol_Code = "Total";
H3.SmartForm.ListViewColumn newCol = new H3.SmartForm.ListViewColumn(
myNewCol_Code,
"总计",
true,
false,
"",
"center",
true,
H3.DataModel.PropertyShowMode.Normal
);
columns.Add(myNewCol_Code, newCol);
}
}
response.Columns = columns;
// 修改列名称示例
Dictionary<string, H3.SmartForm.ListViewColumn> modColumns = new Dictionary<string, H3.SmartForm.ListViewColumn>();
foreach(string key in response.Columns.Keys)
{
if(key == "F0000001")
{
H3.SmartForm.ListViewColumn newCol = new H3.SmartForm.ListViewColumn(
"`F0000001`",
"修改后列名称",
response.Columns[key].Visible,
response.Columns[key].Sortable,
response.Columns[key].Url,
response.Columns[key].Align,
response.Columns[key].IsLabel,
response.Columns[key].ShowMode
);
modColumns.Add("F0000001", newCol);
}
else
{
modColumns.Add(key, response.Columns[key]);
}
}
response.Columns = modColumns;
// 隐藏列示例
if(response.Columns.ContainsKey("SeqNo"))
{
response.Columns.Remove("SeqNo");
}
// 控制筛选条件展示示例
if(response.QueryItems != null)
{
foreach(H3.SmartForm.ListViewQueryItem item in response.QueryItems)
{
if(item.PropertyName == "SeqNo") continue;
item.Visible = false;
}
}
base.OnInit(response);
}
加载列表数据事件
功能描述
支持设置字段颜色(不支持地图视图;若需使用,建议增加空值判断以避免错误)。
接口定义
protected override void OnLoad(H3.SmartForm.LoadListViewResponse response)
参数
| 参数名称 | 是否必填 | 类型 | 描述 |
|---|---|---|---|
response |
是 | H3.SmartForm.LoadListViewResponse |
返回值 |
返回值
无返回值,通过 response 返回数据。
示例
protected override void OnLoad(H3.SmartForm.LoadListViewResponse response)
{
base.OnLoad(response);
if(this.Request.ListScene == H3.SmartForm.ListScene.NormalList)
{
foreach(Dictionary<string, object> data in response.ReturnData)
{
data["SeqNo"] = new H3.SmartForm.ListViewCustomCell(
data["SeqNo"] == null ? "--" : data["SeqNo"].ToString(),
H3.SmartForm.Color.Red
);
}
}
}
执行操作请求事件
功能描述
根据操作编码执行逻辑,接收前端传递参数。
接口定义
protected override void OnSubmit(string actionName,
H3.SmartForm.ListViewPostValue postValue,
H3.SmartForm.SubmitListViewResponse response)
参数
| 参数名称 | 是否必填 | 类型 | 描述 |
|---|---|---|---|
actionName |
是 | string |
自定义操作唯一名称 |
postValue |
是 | H3.SmartForm.ListViewPostValue |
前端传递参数 |
返回值
无返回值,通过 response 返回数据。
示例
protected override void OnSubmit(string actionName, H3.SmartForm.ListViewPostValue postValue, H3.SmartForm.SubmitListViewResponse response)
{
if(actionName == "xxx")
{
string customer = this.Request[“Customer”] + string.Empty;
//获取列表页面选中的数据ID集合
string[] selectedObjectIds = postValue.Data["ObjectIds"] as string[];
string selectedObjectIdsStr = this.Request["ObjectIds"] + string.Empty;
if(response.ReturnData == null)
{
response.ReturnData = new Dictionary<string, object>();
response.ReturnData.Add("currentTime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
response.ReturnData.Add("currentUserId", this.Request.UserContext.UserId);
response.ReturnData["currentUserName"] = this.Request.UserContext.User.Name;
}
}
base.OnSubmit(actionName, postValue, response);
}