PaginatedDataTable参数
PaginatedDataTable({
Key key,
@required this.header,//设置头部
this.actions,
@required this.columns,
this.sortColumnIndex,
this.sortAscending = true,
this.onSelectAll,
this.dataRowHeight = kMinInteractiveDimension,
this.headingRowHeight = 56.0,
this.horizontalMargin = 24.0,
this.columnSpacing = 56.0,
this.initialFirstRowIndex = 0,
this.onPageChanged,
this.rowsPerPage = defaultRowsPerPage,
this.availableRowsPerPage = const <int>[defaultRowsPerPage, defaultRowsPerPage * 2, defaultRowsPerPage * 5, defaultRowsPerPage * 10],
this.onRowsPerPageChanged,
this.dragStartBehavior = DragStartBehavior.start,
@required this.source,
})
import 'package:flutter/material.dart';
import 'datas.dart';
//定义表格数据源的类
class PostDataSource extends DataTableSource {
List<Post> _datas = datas;
int _selectCount = 0;
//定义数据的长度
@override
int get rowCount => _datas.length;
@override
//
bool get isRowCountApproximate => false;
@override
// 选择每行的时候执行
int get selectedRowCount => _selectCount;
@override
DataRow getRow(int index) {
// 每行具体内容
final datasValue=_datas[index];
return DataRow.byIndex(
cells:<DataCell> [
DataCell(Text(datasValue.title) ),
DataCell(Text(datasValue.author) ),
DataCell(Image.network(datasValue.imageUrl) ),
],
index: index,
);
}
}
class PaginatedTableDemo extends StatefulWidget {
@override
_TableDemoState createState() => _TableDemoState();
}
class _TableDemoState extends State<PaginatedTableDemo> {
int _sortIndex = 0;
bool _sortHandle = true;
final PostDataSource _datasSource = PostDataSource();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('表格案例演示'),
),
body: ListView(
children: <Widget>[
PaginatedDataTable(
//表格头部
header: Text('表格分页'),
//每页显示个数
rowsPerPage: 5,
//表格数据
source: _datasSource,
sortColumnIndex: _sortIndex,
//true升序排列,false降序排列
sortAscending: _sortHandle,
columns: [
DataColumn(
//单独设置宽度
label: Container(
width: 100.0,
child: Text('标题'),
),
),
DataColumn(label: Text('作者')),
DataColumn(label: Text('图片')),
],
),
],
),
);
}
}
文章版权声明:除非注明,否则均为
譬如朝露_策温技术开发工作室博客原创文章,转载或复制请以超链接形式并注明出处。
发表评论
侧栏公告
寄语
譬如朝露博客是一个分享前端知识的网站,联系方式11523518。
热评文章
标签列表
热门文章
友情链接