SmartTable 簡單易用的表格框架
表格形式適合大量數(shù)據(jù)的展示(如數(shù)據(jù)庫數(shù)據(jù))。
SmartTable 是基于對(duì)象列表的表格框架。
支持的功能:
- 快速配置自動(dòng)生成表格;
- 自動(dòng)計(jì)算表格寬高;
- 表格列標(biāo)題組合;
- 表格固定左序列、頂部序列、第一行、列標(biāo)題、統(tǒng)計(jì)行;
- 自動(dòng)統(tǒng)計(jì),排序(自定義統(tǒng)計(jì)規(guī)則);
- 表格圖文、序列號(hào)、列標(biāo)題格式化;
- 表格各組成背景、文字、網(wǎng)格、padding 等配置;
- 表格批注;
- 表格內(nèi)容、列標(biāo)題點(diǎn)擊事件;
- 縮放模式和滾動(dòng)模式;
- 注解模式;
- 內(nèi)容多行顯示;
- 分頁模式;
- 首尾動(dòng)態(tài)添加數(shù)據(jù);
- 豐富的格式化;
- 支持二維數(shù)組展示(用于類似日程表,電影選票等);
- 導(dǎo)入 excel(支持顏色,字體,背景,批注,對(duì)齊,圖片等基本 Excel 屬性);
- 表格合并單元 (支持注解合并,支持自動(dòng)合并);
- 支持其他刷新框架 SmartRefreshLayout;
- 可配置表格最小寬度 (小于該寬度自動(dòng)適配);
- 支持直接 List 或數(shù)組字段轉(zhuǎn)列;
- 支持 Json 數(shù)據(jù)直接轉(zhuǎn)換成表格;
- 支持表格網(wǎng)格指定行列顯示;
- 支持自動(dòng)生成表單。
添加 SmartTable 依賴
在項(xiàng)目的 build.gradle 中加入依賴。
dependencies {
...
// 智能表格
api 'com.github.huangyanbin:SmartTable:2.0'
}
增加 SmartTable 控件
在相應(yīng)的 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"
/>
設(shè)置 SmartTable
以 Group 對(duì)象為例(其實(shí)是一個(gè) GreenDao 實(shí)例)
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;
}
}
設(shè)置 SmartTable 參數(shù)(列信息、表名、表格數(shù)據(jù))
final Column<Long> groupIdColumn = new Column<>("組ID (group_id)", "groupId"); // 列名稱,關(guān)聯(lián)的對(duì)象字段
final Column<String> groupNameColumn = new Column<>("組名 (group_name)", "groupName"); // 列名稱,關(guān)聯(lián)的對(duì)象字段
// 加載 GroupBean 對(duì)象列表,過程忽略。 (List<GroupBean> groupBeanList)
TableData<GroupBean> tableData = new TableData<>("GroupBean 表格 (group_table)", // 表格名稱
groupBeanList, // 表格數(shù)據(jù)
groupIdColumn, // 第一列對(duì)應(yīng)的字段
groupNameColumn); // 第二列對(duì)應(yīng)的字段
smartTable.setTableData(tableData); // 表格配置關(guān)聯(lián)到控件中
TableData 的構(gòu)造函數(shù)第一參數(shù)為表格名稱(String);
第二參數(shù)為表格數(shù)據(jù)(List<T>,其中 T 為對(duì)象類型,每個(gè)對(duì)象的數(shù)據(jù)表示一行表格信息);
后續(xù)的參數(shù)則為列信息(需要關(guān)聯(lián) T 對(duì)象內(nèi)部數(shù)據(jù)字段)。

SmartTable表格示例