SmartTable 简单易用的表格框架
表格形式适合大量数据的展示(如数据库数据)。
SmartTable 是基于对象列表的表格框架。
支持的功能:
- 快速配置自动生成表格;
- 自动计算表格宽高;
- 表格列标题组合;
- 表格固定左序列、顶部序列、第一行、列标题、统计行;
- 自动统计,排序(自定义统计规则);
- 表格图文、序列号、列标题格式化;
- 表格各组成背景、文字、网格、padding 等配置;
- 表格批注;
- 表格内容、列标题点击事件;
- 缩放模式和滚动模式;
- 注解模式;
- 内容多行显示;
- 分页模式;
- 首尾动态添加数据;
- 丰富的格式化;
- 支持二维数组展示(用于类似日程表,电影选票等);
- 导入 excel(支持颜色,字体,背景,批注,对齐,图片等基本 Excel 属性);
- 表格合并单元 (支持注解合并,支持自动合并);
- 支持其他刷新框架 SmartRefreshLayout;
- 可配置表格最小宽度 (小于该宽度自动适配);
- 支持直接 List 或数组字段转列;
- 支持 Json 数据直接转换成表格;
- 支持表格网格指定行列显示;
- 支持自动生成表单。
添加 SmartTable 依赖
在项目的 build.gradle 中加入依赖。
dependencies {
...
// 智能表格
api 'com.github.huangyanbin:SmartTable:2.0'
}
增加 SmartTable 控件
在相应的 layout 布局文件中加入
<com.bin.david.form.core.SmartTable
android:id="@+id/smarttable_tables_data"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
/>
设置 SmartTable
以 Group 对象为例(其实是一个 GreenDao 实例)
public class GroupBean {
@Id(autoincrement = true)
@Unique
@Property(nameInDb = "group_id")
private Long groupId;
@Unique
@NotNull
@Property(nameInDb = "group_name")
private String groupName;
@Generated(hash = 1061874704)
public GroupBean(Long groupId, @NotNull String groupName) {
this.groupId = groupId;
this.groupName = groupName;
}
@Generated(hash = 405578774)
public GroupBean() {
}
public Long getGroupId() {
return this.groupId;
}
public void setGroupId(Long groupId) {
this.groupId = groupId;
}
public String getGroupName() {
return this.groupName;
}
public void setGroupName(String groupName) {
this.groupName = groupName;
}
}
设置 SmartTable 参数(列信息、表名、表格数据)
final Column<Long> groupIdColumn = new Column<>("组ID (group_id)", "groupId"); // 列名称,关联的对象字段
final Column<String> groupNameColumn = new Column<>("组名 (group_name)", "groupName"); // 列名称,关联的对象字段
// 加载 GroupBean 对象列表,过程忽略。 (List<GroupBean> groupBeanList)
TableData<GroupBean> tableData = new TableData<>("GroupBean 表格 (group_table)", // 表格名称
groupBeanList, // 表格数据
groupIdColumn, // 第一列对应的字段
groupNameColumn); // 第二列对应的字段
smartTable.setTableData(tableData); // 表格配置关联到控件中
TableData 的构造函数第一参数为表格名称(String);
第二参数为表格数据(List<T>,其中 T 为对象类型,每个对象的数据表示一行表格信息);
后续的参数则为列信息(需要关联 T 对象内部数据字段)。
SmartTable表格示例