Close Menu
Soshace Digital Blog

    Subscribe to Updates

    Get The Latest News, Updates, And Amazing Offers

    What's Hot
    Development

    Implementing Data Privacy Principles in Software Development

    JavaScript

    Streamlining Resource Allocation for Enhanced Project Success

    Programming

    1. Express.js Lessons. Basics and Middleware. Part 1.

    Important Pages:
    • Home
    • About
    • Services
    • Contact Us
    • Privacy Policy
    • Terms & Conditions
    Facebook X (Twitter) Instagram LinkedIn YouTube
    Today's Picks:
    • Scaling Success: Monitoring Indexation of Programmatic SEO Content
    • Leveraging Influencers: Key Drivers in New Product Launches
    • How Privacy-First Marketing Will Transform the Industry Landscape
    • The Impact of Social Proof on Thought Leadership Marketing
    • Balancing Value-Driven Content and Promotional Messaging Strategies
    • Top Influencer Marketing Platforms to Explore in 2025
    • Emerging Trends in Marketing Automation and AI Tools for 2023
    • Strategies to Mitigate Duplicate Content in Programmatic SEO
    Wednesday, September 10
    Facebook X (Twitter) Instagram LinkedIn YouTube
    Soshace Digital Blog
    • Home
    • About
    • Services
    • Contact Us
    • Privacy Policy
    • Terms & Conditions
    Services
    • SaaS & Tech

      Maximizing Efficiency: How SaaS Lowers IT Infrastructure Costs

      August 27, 2025

      Navigating Tomorrow: Innovations Shaping the Future of SaaS

      August 27, 2025

      Maximizing Impact: Strategies for SaaS & Technology Marketing

      August 27, 2025
    • AI & Automation

      Enhancing Customer Feedback Analysis Through AI Innovations

      August 27, 2025

      Navigating the Impact of AI on SEO and Search Rankings

      August 27, 2025

      5 Automation Hacks Every Home Service Business Needs to Know

      May 3, 2025
    • Finance & Fintech

      Critical Missteps in Finance Marketing: What to Avoid

      August 27, 2025

      Analyzing Future Fintech Marketing Trends: Insights Ahead

      August 27, 2025

      Navigating the Complex Landscape of Finance and Fintech Marketing

      August 27, 2025
    • Legal & Compliance

      Exploring Thought Leadership’s Impact on Legal Marketing

      August 27, 2025

      Maximizing LinkedIn: Strategies for Legal and Compliance Marketing

      August 27, 2025

      Why Transparency Matters in Legal Advertising Practices

      August 27, 2025
    • Medical Marketing

      Enhancing Online Reputation Management in Hospitals: A Guide

      August 27, 2025

      Analyzing Emerging Trends in Health and Medical Marketing

      August 27, 2025

      Exploring Innovative Content Ideas for Wellness Blogs and Clinics

      August 27, 2025
    • E-commerce & Retail

      Strategic Seasonal Campaign Concepts for Online and Retail Markets

      August 27, 2025

      Emerging Trends in E-commerce and Retail Marketing Strategies

      August 27, 2025

      Maximizing Revenue: The Advantages of Affiliate Marketing for E-Commerce

      August 27, 2025
    • Influencer & Community

      Leveraging Influencers: Key Drivers in New Product Launches

      August 27, 2025

      Top Influencer Marketing Platforms to Explore in 2025

      August 27, 2025

      Key Strategies for Successful Influencer Partnership Negotiations

      August 27, 2025
    • Content & Leadership

      The Impact of Social Proof on Thought Leadership Marketing

      August 27, 2025

      Balancing Value-Driven Content and Promotional Messaging Strategies

      August 27, 2025

      Analyzing Storytelling’s Impact on Content Marketing Effectiveness

      August 27, 2025
    • SEO & Analytics

      Scaling Success: Monitoring Indexation of Programmatic SEO Content

      August 27, 2025

      Strategies to Mitigate Duplicate Content in Programmatic SEO

      August 27, 2025

      Effective Data Visualization Techniques for SEO Reporting

      August 27, 2025
    • Marketing Trends

      How Privacy-First Marketing Will Transform the Industry Landscape

      August 27, 2025

      Emerging Trends in Marketing Automation and AI Tools for 2023

      August 27, 2025

      Maximizing ROI: Key Trends in Paid Social Advertising

      August 27, 2025
    Soshace Digital Blog
    Blog / JavaScript / POS Tutorial / Create simple POS with React.js, Node.js, and MongoDB #13: Grouping, Sorting, Pagination
    JavaScript

    Create simple POS with React.js, Node.js, and MongoDB #13: Grouping, Sorting, Pagination

    Krissanawat KaewsanmuangBy Krissanawat KaewsanmuangAugust 24, 2020Updated:March 9, 2021No Comments8 Mins Read
    Facebook Twitter Pinterest Telegram LinkedIn Tumblr Email Reddit
    Create simple POS with React.js, Node.js, and MongoDB #13: Grouping, Sorting, Pagination
    Create simple POS with React.js, Node.js, and MongoDB #13: Grouping, Sorting, Pagination
    Share
    Facebook Twitter LinkedIn Pinterest Email Copy Link
    Create simple POS with React.js, Node.js, and MongoDB #13: Grouping, Sorting, Pagination
    Create simple POS with React.js, Node.js, and MongoDB #13: Grouping, Sorting, Pagination

    Defenition: POS – “Point of Sale”. At the point of sale, the merchant calculates the amount owed by the customer, indicates that amount, may prepare an invoice for the customer (which may be a cash register printout), and indicates the options for the customer to make payment.

    In the previous chapter, we integrated react-table to our codebase and replaced the old table. We created a headless Table component so that we can import it to other components and use it easily. In this chapter, we are going to continue from where we left off from the previous chapter. Here, we are going to integrate grouping and sorting features to our react table along with pagination. Before we get started on integrating the respective features to the react-native, we need to work on moving the Table component and add it to the POS machine section. After adding it to the POS machine section, we are going to start with the Sorting feature first.

    So, let us get started!

    Sorting

    In order to add a sorting filter to our react table, we are going to use useSortBy hook. This will handle the sorting task. Hence, we need to import it from the react-table package as directed in the code snippet below:

    import { useTable, useFilters, useSortBy } from "react-table";

    Then, we need to add it to our main function as displayed in the code snippet below:

    export default function Table({ columns, data }) {
        const [filterInput, setFilterInput] = useState("");
        const {
            getTableProps,
            getTableBodyProps,
            headerGroups,
            rows,
            prepareRow,
            setFilter,
            
        } = useTable(
    
            {
                columns,
                data,
            }, useFilters, useSortBy
        );

    Next, we need to attach the sort functionality to the table as directed in the code snippet below:

    <th {...column.getHeaderProps(column.getSortByToggleProps())}>
                                     
               {column.render("Header")}
                  <span>
                    {column.isSorted
                         ? column.isSortedDesc
                                 ? ' 🔽'
                                 : ' 🔼'
                                 : ''}
                   </span>
         </th>

    Hence, we will get the result as displayed in the demo below:

    React table sorting result
    React table sorting result

    Now, we are able to sort the table data based on table headers.

    Grouping

    For the Grouping feature, we need two hooks. They are useGroupBy and useExpanded which we need to import from the react-table as shown below:

    import { useTable, useFilters, useSortBy, useGroupBy, useExpanded} from "react-table";

    Next, we need to attach them to the main method as highlighted in the code snippet below:

    const {
            getTableProps,
            getTableBodyProps,
            headerGroups,
            rows,
            prepareRow,
            setFilter,
        } = useTable(
            {
                columns,
                data,
            }, useFilters, useGroupBy, useSortBy, useExpanded, 
        );

    Now in order to use it in our table, we need to add it to the column header as directed in the code snippet below:

    <th {...column.getHeaderProps(column.getSortByToggleProps())}>
                  {column.canGroupBy ? (
                 // If the column can be grouped, let's add a toggle
                     <span {...column.getGroupByToggleProps()}>
                        {column.isGrouped ? '🛑 ' : '👊 '}
                      </span>
                   ) : null}

    Hence, we will get the result as displayed in the following demo:

    Read More:  React Native AsyncStorage Example: When I Die App
    React table grouping result
    React table grouping result

    Here, we can see the count number on each column entry after grouping.

    Pagination

    Integrating pagination into our table requires a lot of work. First, we need to seed some data to our database. But, first, we need to install the faker plugin. For installation, we need to run the following command in our project terminal:

    npm i faker

    Now in api_pos_machine.js, we import the faker plugin as shown in the code snippet below:

    var faker = require('faker');

    Next, we need to work on the function code which is meant to add a new row to the table. In that function, we need to add the code from the code snippet below in order to generate the seed data:

    let pos = [];
        for (let i = 0; i < 100; i += 1) {
          let alias = faker.random.word();
          let serial_number = faker.random.uuid();
          let newPos = {
            alias,
            serial_number,
          };
          pos.push(newPos);
    
          // visual feedback always feels nice!
          console.log(newPos);
        }
     let doc = await POS_Machine.create(pos);

    Here, we are iterating with limit 100 and adding a random word and uuid to the newPos object variable. The newPost is then added to the pos array.

    After seeding the data, we are going to see tons of row on the table as displayed in the screenshot demo below:

    Result for seed database
    Result for seed database

    Now, we can start implementing pagination on our Table component.

    First, we need to import usePagination hook from the react-table package as directed in the code snippet below:

    import { useTable, useFilters, useSortBy, useGroupBy, useExpanded, usePagination } from "react-table";

    Then, we need to add all pagination functions to our main function as highlighted in the code snippet below:

    export default function Table({ columns, data }) {
        const [filterInput, setFilterInput] = useState("");
        const {
            getTableProps,
            getTableBodyProps,
            headerGroups,
            rows,
            prepareRow,
            setFilter,
            page, // Instead of using 'rows', we'll use page,
            // which has only the rows for the active page
    
            // The rest of these things are super handy, too ;)
            canPreviousPage,
            canNextPage,
            pageOptions,
            pageCount,
            gotoPage,
            nextPage,
            previousPage,
            setPageSize,
            state: { pageIndex, pageSize },
        } = useTable(
    
            {
                columns,
                data,
                initialState: { pageIndex: 2 },
            }, useFilters, useGroupBy, useSortBy, useExpanded, usePagination
        );

    Now inside the table body, we need to change row map to page map as highlighted in the code snippet below:

    <tbody {...getTableBodyProps()}>
                        {page.map((row, i) => {
                            prepareRow(row);
                            return (

    Next, we need to add pagination control at the bottom of the table view. We can add plain pagination control using HTML only. But fortunately, we have a Bootstrap CSS framework providing us with a modern and intuitive style for pagination control. This will save us tons of time on design. Here, we have three-part of pagination control. First for navigating between screens which are forward and backward navigation. This can be implemented using code from the following code snippet:

    <form className="inline">
                    <div className="form-row">
                        <div className="form-group input-group col-md-2">
                            <ul className="pagination">
                                <li class={!canPreviousPage ? "page-item disabled" : "page-item "} >
                                    <a className="page-link" onClick={() => gotoPage(0)} >{'<<'}</a>
                                </li>
                                <li class={!canPreviousPage ? "page-item disabled" : "page-item "}>
                                    <a className="page-link" onClick={() => previousPage()} >{'<'}</a>
                                </li>
                                <li class={!canNextPage ? "page-item disabled" : "page-item "}>
                                    <a className="page-link" onClick={() => nextPage()} >{'>'}</a>
                                </li>
                                <li class={!canNextPage ? "page-item disabled" : "page-item "}>
                                    <a className="page-link" onClick={() => gotoPage(pageCount - 1)} >{'>>'}</a>
                                </li>
                            </ul>
                        </div>

    Hence, we will get the result as displayed in the following demo:

    Read More:  Where to Hire Remote Developers

    React table pagination navigate result
    React table pagination navigate result

    We can notice that the page changes along with page number as we click on forward and backward buttons. Secondly, we need to add the pagination control for forms to select the page that we need to navigate to. This can be implemented using the code from the following code snippet:

    <div className="form-group input-group col-md-2">
                            <input
                                className="form-control"
                                type="number"
                                defaultValue={pageIndex + 1}
                                onChange={e => {
                                    const page = e.target.value ? Number(e.target.value) - 1 : 0
                                    gotoPage(page)
                                }}
                            />
                   </div>

    Hence, we will get the result as shown in the demo below:

    React table pagination select page result
    React table pagination select page result

    Here, we can see that the page changes as we change the page number. Lastly, we need to add the pagination control to the page size. With this, we will be able to choose the number of rows that we need to see on the table. In order to implement this, we can use the code from the following code snippet:

    <div className="form-group input-group col-md-2">
                            <select
                                className="custom-select"
                                value={pageSize}
                                onChange={e => {
                                    setPageSize(Number(e.target.value))
                                }}
                            >
                                {[10, 20, 30, 40, 50].map(pageSize => (
                               <option key={pageSize} value={pageSize}>
                                        Show {pageSize}
                                    </option>
                                ))}
                            </select>
                        </div>
                        <span>
                            Page{' '}
                            <strong>
                                {pageIndex + 1} of {pageOptions.length}
                            </strong>{' '}
                        | Go to page:{' '}
                        </span>
                    </div>
                </form>

    Hence, we will get the result as displayed in the following demo.

    React table pagination select page size
    React table pagination select page size

    Now, we can choose the number of rows that we want displayed on the table. Finally, we have successfully integrated the sorting, grouping, and pagination control features into our Table component.

    Conclusion

    We made our table view more intuitive and power-packed in this tutorial. We got the detailed stepwise guidance on integrating the sorting, grouping, and pagination control to our react table. We have the use of hooks along with the faker plugin to integrate the sorting and grouping. For pagination, we used bootstrap for styling purposes and integrated pagination control three-ways. These features in our table will make it more dynamic and full-fledged.

    The coding implementations used in this tutorial chapter are available on Github for both frontend and backend.

    See you in the next chapter! Good day folks!

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Krissanawat Kaewsanmuang
    • Website
    • X (Twitter)

    Developer Relation @instamobile.io

    Related Posts

    Streamlining Resource Allocation for Enhanced Project Success

    December 18, 2024

    Conducting Effective Post-Project Evaluations: A Guide

    December 16, 2024

    Strategies for Keeping Projects on Track and Meeting Deadlines

    December 10, 2024
    Leave A Reply Cancel Reply

    You must be logged in to post a comment.

    Stay In Touch
    • Facebook
    • Twitter
    • Pinterest
    • Instagram
    • YouTube
    • Vimeo
    Don't Miss
    Tips July 17, 2019

    Who is a Developer Advocate?

    What’s advocacy and how does it relate to web development? Is a developer advocate just another fancy term for a technical evangelist, technical leader, or a senior software engineer? Is advocacy just a nice trendy name currently in fashion? Or is it one of those vocables that have entered the web development terminology for good? These and other questions, we’ll attempt to answer within this piece.

    Interview With Oleg – Soshace Team

    December 8, 2016

    Работа с заказчиком

    December 31, 2015

    Introduction to the Best Code Playgrounds: JSFiddle, Codepen, and CodeSandbox

    June 19, 2019

    Categories

    • AI & Automation
    • Angular
    • ASP.NET
    • AWS
    • B2B Leads
    • Beginners
    • Blogs
    • Business Growth
    • Case Studies
    • Comics
    • Consultation
    • Content & Leadership
    • CSS
    • Development
    • Django
    • E-commerce & Retail
    • Entrepreneurs
    • Entrepreneurship
    • Events
    • Express.js
    • Facebook Ads
    • Finance & Fintech
    • Flask
    • Flutter
    • Franchising
    • Funnel Strategy
    • Git
    • GraphQL
    • Home Services Marketing
    • Influencer & Community
    • Interview
    • Java
    • Java Spring
    • JavaScript
    • Job
    • Laravel
    • Lead Generation
    • Legal & Compliance
    • LinkedIn
    • Machine Learning
    • Marketing Trends
    • Medical Marketing
    • MSP Lead Generation
    • MSP Marketing
    • NestJS
    • Next.js
    • Node.js
    • Node.js Lessons
    • Paid Advertising
    • PHP
    • Podcasts
    • POS Tutorial
    • Programming
    • Programming
    • Python
    • React
    • React Lessons
    • React Native
    • React Native Lessons
    • Recruitment
    • Remote Job
    • SaaS & Tech
    • SEO & Analytics
    • Soshace
    • Startups
    • Swarm Intelligence
    • Tips
    • Trends
    • Vue
    • Wiki
    • WordPress
    Top Posts

    Malesuada Proin Libero Nunc Consequat Interdum

    JavaScript January 28, 2020

    5 Tips from Famous Entrepreneurs to Instantly Boost Your Productivity

    Entrepreneurship February 28, 2019

    28 Sample Interview Questions for JavaScript Developers | Theory and Practice

    Interview February 27, 2019

    GraphQL

    Programming October 5, 2017

    Subscribe to Updates

    Get The Latest News, Updates, And Amazing Offers

    About Us
    About Us

    Soshace Digital delivers comprehensive web design and development solutions tailored to your business objectives. Your website will be meticulously designed and developed by our team of seasoned professionals, who combine creative expertise with technical excellence to transform your vision into a high-impact, user-centric digital experience that elevates your brand and drives measurable results.

    7901 4th St N, Suite 28690
    Saint Petersburg, FL 33702-4305
    Phone: 1(877)SOSHACE

    Facebook X (Twitter) Instagram Pinterest YouTube LinkedIn
    Our Picks
    React

    Understanding Data-binding in React and Angular

    Programming

    50+ Amazing Tools and Online Resources for Web Developers | Bookmark Now!

    Interview

    Tips and Tricks for a Newbie at Web Development: How to Prepare for the Interview

    Most Popular

    Strategies for Overcoming Recruitment Challenges in 2023

    Recruitment

    Node.js Lesson 10: Nodejs as a Web Server

    Node.js

    8. Уроки Node.js. Наследование от ошибок Error

    Programming
    © 2025 Soshace Digital.
    • Home
    • About
    • Services
    • Contact Us
    • Privacy Policy
    • Terms & Conditions

    Type above and press Enter to search. Press Esc to cancel.