Skip to content

Commit 431d58f

Browse files
authored
add:td_table增加自定义表尾属性 (Tencent#776)
1 parent b3bcc97 commit 431d58f

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed

tdesign-component/example/lib/page/td_table_page.dart

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ class TDTablePage extends StatelessWidget {
8181
ExampleItem(desc: '空数据表格', builder: _emptyTable),
8282
ExampleItem(desc: '加载动画表格', builder: _loadingTable),
8383
ExampleItem(desc: '可选表格+默认选中', builder: _selectTable),
84+
ExampleItem(desc: '自定义表尾组件', builder: (context) => ShowFooterTable()),
8485
],
8586
);
8687
}
@@ -381,3 +382,73 @@ class TDTablePage extends StatelessWidget {
381382
);
382383
}
383384
}
385+
class ShowFooterTable extends StatefulWidget {
386+
const ShowFooterTable({super.key});
387+
388+
@override
389+
State<ShowFooterTable> createState() => _ShowFooterTableState();
390+
}
391+
392+
class _ShowFooterTableState extends State<ShowFooterTable> {
393+
var _hasMore = true;
394+
var _data = [];
395+
var _pageIndex = 1;
396+
397+
@override
398+
void initState() {
399+
super.initState();
400+
_fetchData();
401+
}
402+
403+
Future<void> _fetchData() async {
404+
setState(() {
405+
_hasMore = _pageIndex <= 2;
406+
});
407+
if (!_hasMore) {
408+
return;
409+
}
410+
setState(() {
411+
_data.addAll(_getData(10));
412+
});
413+
}
414+
415+
@override
416+
Widget build(BuildContext context) {
417+
return _showFooterTable(context);
418+
}
419+
420+
@Demo(group: 'table')
421+
Widget _showFooterTable(BuildContext context) {
422+
return TDTable(
423+
height: 100,
424+
footerWidget: _hasMore ? TDText('加载更多...') : TDText('没有更多数据了'),
425+
onScroll: (controller) {
426+
if (controller.position.pixels == controller.position.maxScrollExtent &&
427+
_hasMore) {
428+
_pageIndex += 1;
429+
_fetchData();
430+
}
431+
},
432+
data: _data,
433+
columns: [
434+
TDTableCol(title: '标题', colKey: 'title1'),
435+
TDTableCol(title: '标题', colKey: 'title2'),
436+
TDTableCol(title: '标题', colKey: 'title3'),
437+
TDTableCol(title: '标题', colKey: 'title4')
438+
],
439+
);
440+
}
441+
442+
List<dynamic> _getData(int index) {
443+
var data = <dynamic>[];
444+
for (var i = 0; i < 10; i++) {
445+
data.add({
446+
'title1': '内容',
447+
'title2': '内容',
448+
'title3': '内容',
449+
'title4': '内容',
450+
});
451+
}
452+
return data;
453+
}
454+
}

tdesign-component/lib/src/components/table/td_table.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class TDTable extends StatefulWidget {
2121
this.loading = false,
2222
this.loadingWidget,
2323
this.showHeader = true,
24+
this.footerWidget,
2425
this.stripe = false,
2526
this.backgroundColor,
2627
this.width,
@@ -58,6 +59,9 @@ class TDTable extends StatefulWidget {
5859
/// 是否显示表头
5960
final bool? showHeader;
6061

62+
/// 自定义表尾
63+
final Widget? footerWidget;
64+
6165
/// 斑马纹
6266
final bool? stripe;
6367

@@ -204,6 +208,9 @@ class TDTableState extends State<TDTable> {
204208
child: Row(children: row),
205209
));
206210
}
211+
if (widget.footerWidget != null){
212+
cells.add(widget.footerWidget!);
213+
}
207214
return Column(
208215
children: cells,
209216
);

0 commit comments

Comments
 (0)