Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pagination not working ? #30

Closed
Mapk26 opened this issue Apr 14, 2021 · 1 comment
Closed

Pagination not working ? #30

Mapk26 opened this issue Apr 14, 2021 · 1 comment

Comments

@Mapk26
Copy link

Mapk26 commented Apr 14, 2021

Hi,

thanks for this package.

I'm trying to use the pagination but I can't find out how it works.
In the demo version https://rodydavis.github.io/data_tables/#/
at the bottom it shows 1-40 of 200 but the next button is disabled. I have the same "issue"

Should I manage pagination by myself with handleNext callback?

Thanks

@Mapk26 Mapk26 changed the title Pagination not working on web? Pagination not working ? Apr 14, 2021
@rodydavis
Copy link
Owner

I updated the example for you, but in short it is a stateless data table so you need to handle that:

class JsonExample extends StatefulWidget {
  @override
  _JsonExampleState createState() => _JsonExampleState();
}

class _JsonExampleState extends State<JsonExample> {
  int _rowsPerPage = 100;
  int _sortColumnIndex;
  bool _sortAscending = true;
  List<Map<String, dynamic>> _items = [];
  int _rowsOffset = 0;

  @override
  void initState() {
    _items = List.from(jsonDecode(JSON_DATA));
    super.initState();
  }

  int index = 0;
  @override
  Widget build(BuildContext context) {
    final _rows = min(40, _items.length);
    return Scaffold(
      appBar: AppBar(
        title: const Text('Data Table Example'),
      ),
      // body: buildDataTable(),
      body: _items == null || _items.isEmpty
          ? const Center(child: CircularProgressIndicator())
          : NativeDataTable.fromJson(
              showSelect: false,
              showSort: false,
              items: _items,
              firstRowIndex: index,
              rowsPerPage: _rows,
              handleNext: () {
                if (mounted) {
                  setState(() {
                    if (index == _items.length - 1) {
                      index = _items.length - 1;
                    } else {
                      index += _rows;
                    }
                  });
                }
              },
              handlePrevious: () {
                if (mounted) {
                  setState(() {
                    if (index == 0) {
                      index = 0;
                    } else {
                      index -= _rows;
                    }
                  });
                }
              },
            ),
    );
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants