Giter VIP home page Giter VIP logo

scrollable_table_view's Introduction

This is a multi axis scrollable data table, that allows you to scroll on both the vertical and horizontal axis, with the header remaining static on the vertical axis. Please look at the demo below.

Features

Demo

This widget serves the same purpose as a DataTable, with the advantage that it can scroll in both the horizontal and vertical axis, while maintaining the vertical position of the header.

Note

For more complex features like freezing columns and rows, kindly take a look at the data_table_2 package

Getting started

Simply add into your dependencies the following line.

dependencies:
  scrollable_table_view: <latest-version>

Usage

ScrollableTableView(
  headers: [
    "product_id",
    "product_name",
    "price",
  ].map((label) {
    return TableViewHeader(
      label: label,
    );
  }).toList(),
  rows: [
    ["PR1000", "Milk", "20.00"],
    ["PR1001", "Soap", "10.00"],
  ].map((record) {
    return TableViewRow(
      height: 60,
      cells: record.map((value) {
        return TableViewCell(
          child: Text(value),
        );
      }).toList(),
    );
  }).toList(),
);

Pagination

Pagination is supported from version 1.0.0-beta. First, initialize a PaginationController as follows:

final PaginationController paginationController = PaginationController(
    rowCount: many_products.length,
    rowsPerPage: 10,
  );

Next, initialize your table and pass the pagination controller to the paginationController parameter:

ScrollableTableView(
  paginationController: paginationController,
  headers: labels.map((label) {
    return TableViewHeader(
      label: label,
    );
  }).toList(),
  rows: many_products.map((product) {
    return TableViewRow(
      height: 60,
      cells: labels.map((label) {
        return TableViewCell(
          child: Text(product[label] ?? ""),
        );
      }).toList(),
    );
  }).toList(),
)

With the above setup, navigate forward and backwards using paginationController.next() and paginationController.backwards() respectively. To jump to a page directly, use paginationController.jumpTo(pageToJumpTo).

For the full example, go to the main.dart file in the example project.

Additional information

GitHub Repo: https://github.com/herbertamukhuma/scrollable_table_view Raise Issues and Feature requests: https://github.com/herbertamukhuma/scrollable_table_view/issues

Common Issues

  1. Loading too many records: From version 1.0.0-beta, pagination has been implemented. Kindly use this to avoid loading too many records at a time, which will inturn overwhelm your app.

scrollable_table_view's People

Contributors

herbertamukhuma avatar

Stargazers

 avatar Mauro Soria avatar Hasani avatar Rezwan avatar Yosof avatar  avatar Jemal Rashidi avatar Sergio García Sánchez  avatar Mazen Mohamed avatar Hatem Ragab avatar  avatar Ilyas LEFEBVRE avatar Kouki Badr avatar Can H. Tartanoglu avatar Teber Mohammed Tahar avatar

Watchers

Yosof avatar  avatar

scrollable_table_view's Issues

how to click each row of table

scrollable_table_veiw library is awesome for scroll horizontal and vertically but I'm not able to click and take a position on each row of table?

ScrollableTableView Issue

I have added large data and then its not scrolling (vertically) properly initially it working perfect for few number of rows & column

current page in Pagination did not change

I am using provider as a state Management,and the following is my code:

` Widget build(BuildContext context) {
print("Build PaginationController");
final p = context.watch();
PaginationController _paginationController=PaginationController(
rowCount: p.data.isEmpty ? 16 : p.data.length,
rowsPerPage:ItemUtils.calculateMaxRows(context),
);
return Scaffold(
body: Column(
children: [
PosHeaderBuilder(
code: widget.code,
dataLength: p.data.length,
icon: widget.iconData,
title: p.title,
onSearch: (x) async {
if (x.isNotEmpty) {
var c = p.data.where((e) =>
e.name!.contains(x) || e.id.toString().contains(x));
p.data = (c.toList());
} else {
await p.loadList();
}
p.refresh();
},
onRefresh: p.init,
context: context,
),
Divider(height: 2, thickness: 0.5),
Expanded(
child: ScrollableTableView(
// paginationController: _paginationController(p, context),
paginationController: _paginationController,
rowDividerHeight: 3,
headerBackgroundColor: kBackgroundColor,
headers: ItemUtils.generateHeaderList(widget.code, p).map((column) {
return TableViewHeader(
textStyle: TextStyle(
fontWeight: FontWeight.w700,
fontFamily: 'OpenSans',
color: Colors.black,
fontSize: 18,
),
minWidth: 80,
width: 150,
label: column,
);
}).toList(),
rows: !p.isLoading
? p.data.map((item) {
return TableViewRow(
height: 30,
cells: [
TableViewCell(
child: Container(
margin: EdgeInsets.symmetric(horizontal: 10),
child: Text(
(p.data.indexOf(item) + 1).toString()?? '',
textAlign: TextAlign.center,
style: TextStyle(fontWeight: FontWeight.bold),
),
),
),
TableViewCell(
child: Text(
item.itemNo ?? '-',
textAlign: TextAlign.center,
style: TextStyle(fontWeight: FontWeight.bold),
),
),
TableViewCell(
child: Text(
item.name ?? '-',
textAlign: TextAlign.center,
style: TextStyle(fontWeight: FontWeight.bold),
),
),
TableViewCell(
child: Text(
Instance.warehouses
.firstWhere(
(e) => e.id == item.warehouseId,
orElse: () => Warehouse(),
)
.title ??
'-',
textAlign: TextAlign.center,
style: TextStyle(fontWeight: FontWeight.bold),
),
),
TableViewCell(
child: Text(
Instance.classifications
.firstWhere(
(e) => e.id == item.classificationId,
orElse: () => Classification(),
)
.title ??
'-',
textAlign: TextAlign.center,
style: TextStyle(fontWeight: FontWeight.bold),
),
),
TableViewCell(
child: Text(
item.count?.toString() ?? '-',
textAlign: TextAlign.center,
style: TextStyle(fontWeight: FontWeight.bold),
),
),
TableViewCell(
child: Container(
margin: EdgeInsets.symmetric(horizontal: 10),
child: Checkbox(
value: item.isFavorite ?? false,
onChanged: (x) {
// p.isFavorite = (x)!;
if (isEdit(widget.code)) {
item?.isFavorite = x;
HelpPos.changeStatus(context, p, item,
callBack: (x) async {
await HiveRepository.addItemsCashing(
convertItemToLocal([item]));
await p.loadList();
p.refresh();
});
}
}),
),
),
TableViewCell(
child: Container(
margin: EdgeInsets.symmetric(horizontal: 10),
child: Checkbox(
value: item.status ?? false,
onChanged: (x) {
if (isEdit(widget.code)) {
item.status = x!;
HelpPos.changeStatus(context, p, item,
callBack: (x) async {
await HiveRepository.addItemsCashing(
convertItemToLocal([item]));
await p.loadList();
p.refresh();
});
}
}),
),
),
TableViewCell(
child: Responsive.isDesktop(context)
? Row(
crossAxisAlignment:
CrossAxisAlignment.center,
mainAxisAlignment:
MainAxisAlignment.center,
children: [
if (isEdit(widget.code))
transactionEntity(
onTap: () => p.edit(context, item),
icon: Icons.edit,
),
SizedBox(width: 5),
if (isDelete(widget.code))
transactionEntity(
onTap: () =>
p.delete(context, item),
icon: Icons.delete,
),
transactionEntity(
onTap: () => p.showS(context, item),
icon: Icons.info,
),
],
)
: buildPopupMenuActions([
if (isEdit(widget.code))
buildPopupMenuItem(
title: 'تعديل',
iconData: Icons.edit,
onClick: () => p.edit(context, item),
context: context,
),
if (isDelete(widget.code))
buildPopupMenuItem(
title: 'حذف',
iconData: CupertinoIcons.delete,
onClick: () =>
p.delete(context, item),
context: context,
),
buildPopupMenuItem(
title: 'تفاصيل الصنف',
iconData: CupertinoIcons.info,
onClick: () => p.showS(context, item),
context: context,
),
]),
),
],
);
}).toList()
: generateShimmerLoading(length: 16).map((lod) {
return TableViewRow(height: 30, cells: [
TableViewCell(
child: lod,
),
TableViewCell(
child: lod,
),
TableViewCell(
child: lod,
),
TableViewCell(
child: lod,
),
TableViewCell(
child: lod,
),
TableViewCell(
child: lod,
),
TableViewCell(
child: lod,
),
TableViewCell(
child: lod,
),
TableViewCell(
child: lod,
),
]);
}).toList(),
),
),
],
),
persistentFooterButtons: [
WebPagination(
displayItemCount: 3,
onPageChanged: (int page) {

            setState(() {
              // _paginationController(p, context).jumpTo(page);
              _paginationController.jumpTo(page);
              _paginationController.value=page;
              _paginationController.addListener(() {
                _paginationController.jumpTo(page);
                _paginationController.value=page;
              });
              _paginationController.notifyListeners();
              _paginationController.next();
              print("Has Listner :${_paginationController.hasListeners}");
              p.notifyListeners();
               p.refresh();
            });
            print(
                "WebPagination Current page :${_paginationController.currentPage}");
          },
          currentPage:_paginationController.currentPage,
          totalPage:_paginationController.pageCount)
    ]
);

}
` The data in next page did not display,becuase the current page did not updated,, so what the problem?

No TabController for TabBarView.

======== Exception caught by widgets library =======================================================
The following assertion was thrown building _BodyBuilder:
No TabController for TabBarView.

When creating a TabBarView, you must either provide an explicit TabController using the "controller" property, or you must ensure that there is a DefaultTabController above the TabBarView.
In this case, there was neither an explicit controller nor a default controller.
The relevant error-causing widget was:
Scaffold Scaffold:file:///C:/Users/Dev/StudioProjects/assignment/lib/test.dart:27:12
When the exception was thrown, this was the stack:
#0 _TabBarViewState._updateTabController. (package:flutter/src/material/tabs.dart:1386:9)
#1 _TabBarViewState._updateTabController (package:flutter/src/material/tabs.dart:1395:6)
#2 _TabBarViewState.didChangeDependencies (package:flutter/src/material/tabs.dart:1416:5)
#3 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4963:11)
#4 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4781:5)
#5 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3817:16)
#6 Element.updateChild (package:flutter/src/widgets/framework.dart:3545:20)
#7 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4832:16)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.