Guest User

React bootstrap table with pagination

a guest
Apr 15th, 2020
309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, { useState } from "react";
  2.  
  3. // Bootstrap
  4. import { Container, Row, Col, Form } from "react-bootstrap";
  5. import BootstrapTable from "react-bootstrap-table-next";
  6. import paginationFactory, {
  7.   PaginationProvider
  8. } from "react-bootstrap-table2-paginator";
  9. import "react-bootstrap-table-next/dist/react-bootstrap-table2.min.css";
  10. import "react-bootstrap-table2-paginator/dist/react-bootstrap-table2-paginator.min.css";
  11.  
  12. // Components
  13. import { CustomSelect } from "@components";
  14.  
  15. // Seed
  16. import { mainFilters } from "@seed";
  17. const products = [
  18.   {
  19.     id: 1,
  20.     description: "product 1",
  21.     jacket: "PVC",
  22.     jacketColor: "Zwart",
  23.     shielding: <img height={24} src="./assets/crossIcon.svg" />,
  24.     hfFree: <img height={24} src="./assets/checkIcon.svg" />,
  25.     ULStyle: <img height={24} src="./assets/crossIcon.svg" />,
  26.     moreInfo: <a href="#">Meer informatie</a>
  27.   },
  28.   {
  29.     id: 2,
  30.     description: "product 2",
  31.     jacket: "PUR",
  32.     jacketColor: "Zwart",
  33.     shielding: <img height={24} src="./assets/crossIcon.svg" />,
  34.     hfFree: <img height={24} src="./assets/checkIcon.svg" />,
  35.     ULStyle: <img height={24} src="./assets/crossIcon.svg" />,
  36.     moreInfo: <a href="#">Meer informatie</a>
  37.   },
  38.   {
  39.     id: 3,
  40.     description: "product 3",
  41.     jacket: "PUR",
  42.     jacketColor: "Zwart",
  43.     shielding: <img height={24} src="./assets/crossIcon.svg" />,
  44.     hfFree: <img height={24} src="./assets/checkIcon.svg" />,
  45.     ULStyle: <img height={24} src="./assets/crossIcon.svg" />,
  46.     moreInfo: <a href="#">Meer informatie</a>
  47.   },
  48.   {
  49.     id: 4,
  50.     description: "product 4",
  51.     jacket: "PUR",
  52.     jacketColor: "Zwart",
  53.     shielding: <img height={24} src="./assets/crossIcon.svg" />,
  54.     hfFree: <img height={24} src="./assets/checkIcon.svg" />,
  55.     ULStyle: <img height={24} src="./assets/crossIcon.svg" />,
  56.     moreInfo: <a href="#">Meer informatie</a>
  57.   },
  58.   {
  59.     id: 5,
  60.     description: "product 5",
  61.     jacket: "PVC",
  62.     jacketColor: "Zwart",
  63.     shielding: <img height={24} src="./assets/crossIcon.svg" />,
  64.     hfFree: <img height={24} src="./assets/checkIcon.svg" />,
  65.     ULStyle: <img height={24} src="./assets/crossIcon.svg" />,
  66.     moreInfo: <a href="#">Meer informatie</a>
  67.   },
  68.   {
  69.     id: 6,
  70.     description: "product 6",
  71.     jacket: "PVC",
  72.     jacketColor: "Zwart",
  73.     shielding: <img height={24} src="./assets/crossIcon.svg" />,
  74.     hfFree: <img height={24} src="./assets/checkIcon.svg" />,
  75.     ULStyle: <img height={24} src="./assets/crossIcon.svg" />,
  76.     moreInfo: <a href="#">Meer informatie</a>
  77.   },
  78.   {
  79.     id: 7,
  80.     description: "product 7",
  81.     jacket: "PVC",
  82.     jacketColor: "Zwart",
  83.     shielding: <img height={24} src="./assets/crossIcon.svg" />,
  84.     hfFree: <img height={24} src="./assets/checkIcon.svg" />,
  85.     ULStyle: <img height={24} src="./assets/crossIcon.svg" />,
  86.     moreInfo: <a href="#">Meer informatie</a>
  87.   },
  88.   {
  89.     id: 8,
  90.     description: "product 8",
  91.     jacket: "PVC",
  92.     jacketColor: "Zwart",
  93.     shielding: <img height={24} src="./assets/crossIcon.svg" />,
  94.     hfFree: <img height={24} src="./assets/checkIcon.svg" />,
  95.     ULStyle: <img height={24} src="./assets/crossIcon.svg" />,
  96.     moreInfo: <a href="#">Meer informatie</a>
  97.   },
  98.   {
  99.     id: 9,
  100.     description: "product 9",
  101.     jacket: "PVC",
  102.     jacketColor: "Zwart",
  103.     shielding: <img height={24} src="./assets/crossIcon.svg" />,
  104.     hfFree: <img height={24} src="./assets/checkIcon.svg" />,
  105.     ULStyle: <img height={24} src="./assets/crossIcon.svg" />,
  106.     moreInfo: <a href="#">Meer informatie</a>
  107.   },
  108.   {
  109.     id: 10,
  110.     description: "product 10",
  111.     jacket: "PUR",
  112.     jacketColor: "Zwart",
  113.     shielding: <img height={24} src="./assets/crossIcon.svg" />,
  114.     hfFree: <img height={24} src="./assets/checkIcon.svg" />,
  115.     ULStyle: <img height={24} src="./assets/crossIcon.svg" />,
  116.     moreInfo: <a href="#">Meer informatie</a>
  117.   },
  118.   {
  119.     id: 11,
  120.     description: "product 11",
  121.     jacket: "PUR",
  122.     jacketColor: "Zwart",
  123.     shielding: <img height={24} src="./assets/crossIcon.svg" />,
  124.     hfFree: <img height={24} src="./assets/checkIcon.svg" />,
  125.     ULStyle: <img height={24} src="./assets/crossIcon.svg" />,
  126.     moreInfo: <a href="#">Meer informatie</a>
  127.   },
  128.   {
  129.     id: 12,
  130.     description: "product 12",
  131.     jacket: "PUR",
  132.     jacketColor: "Zwart",
  133.     shielding: <img height={24} src="./assets/crossIcon.svg" />,
  134.     hfFree: <img height={24} src="./assets/checkIcon.svg" />,
  135.     ULStyle: <img height={24} src="./assets/crossIcon.svg" />,
  136.     moreInfo: <a href="#">Meer informatie</a>
  137.   },
  138.   {
  139.     id: 13,
  140.     description: "product 13",
  141.     jacket: "PUR",
  142.     jacketColor: "Zwart",
  143.     shielding: <img height={24} src="./assets/crossIcon.svg" />,
  144.     hfFree: <img height={24} src="./assets/checkIcon.svg" />,
  145.     ULStyle: <img height={24} src="./assets/cr.svg" />,
  146.     moreInfo: <a href="#">Meer informatie</a>
  147.   }
  148. ];
  149. const columns = [
  150.   {
  151.     dataField: "id",
  152.     text: "Product ID",
  153.     sort: true
  154.   },
  155.   {
  156.     dataField: "description",
  157.     text: "Omschrijving",
  158.     sort: true
  159.   },
  160.   {
  161.     dataField: "jacket",
  162.     text: "Mantel"
  163.   },
  164.   {
  165.     dataField: "jacketColor",
  166.     text: "Mantelkleur"
  167.   },
  168.   {
  169.     dataField: "shielding",
  170.     text: "Afscherming"
  171.   },
  172.   {
  173.     dataField: "hfFree",
  174.     text: "Halogeenvrij"
  175.   },
  176.   {
  177.     dataField: "ULStyle",
  178.     text: "UL / CSA (UL)"
  179.   },
  180.   {
  181.     dataField: "moreInfo",
  182.     text: ""
  183.   }
  184. ];
  185.  
  186. const Home = props => {
  187.   const [state, setState] = useState({
  188.     amount_of_vains: [
  189.       { name: "1", value: "one_vain" },
  190.       { name: "2", value: "two_vains" }
  191.     ],
  192.     cross_section: [
  193.       { name: "0.05", value: "0.05" },
  194.       { name: "0.10", value: "0.10" }
  195.     ],
  196.     jacket: [
  197.       { name: "PUR", value: "PUR" },
  198.       { name: "PUR FHF", value: "PUR_FHF" }
  199.     ],
  200.     jacketColor: [
  201.       { name: "Zwart", value: "black" },
  202.       { name: "Blauw", value: "blue" }
  203.     ],
  204.     shielding: [
  205.       { name: "Ja", value: "yes" },
  206.       { name: "Nee", value: "no" }
  207.     ],
  208.     hfFree: [
  209.       { name: "Ja", value: "yes" },
  210.       { name: "Nee", value: "no" }
  211.     ],
  212.     ULStyle: [
  213.       { name: "Ja", value: "yes" },
  214.       { name: "Nee", value: "no" }
  215.     ],
  216.  
  217.     selectedVains: null,
  218.     selectedCrossSection: null,
  219.     selectedJacked: null,
  220.     selectedJackedColor: null,
  221.     selectedShielding: null,
  222.     selectedHF: null,
  223.     selectedULStyle: null
  224.   });
  225.  
  226.   return (
  227.     <Container style={{ width: "65vw" }}>
  228.       <Row className="justify-content-start">
  229.         <Col xs={6}>
  230.           {/* Configurator Title introduction */}
  231.           <h2 className="mb-2">
  232.             ZOEK, SELECTEER EN CONFIGUREER DE KABEL NAAR UW WENSEN
  233.           </h2>
  234.  
  235.           {/* Filter introduction */}
  236.           <h5>FILTERS</h5>
  237.           <p>
  238.             Selecteer de waardes die voor u kabel van toepassing zijn. Op basis
  239.             van deze waardes filteren wij onze producten en tonen wij u de kabel
  240.             die het beste bij u wensen aansluit. Mocht u vragen hebben over de
  241.             configurator of advies willen hebben, neem dan telefonisch contact
  242.             met ons op via <a href="test">+31 (0)162 - 523 436.</a>
  243.           </p>
  244.         </Col>
  245.  
  246.         <Col xs={12}>
  247.           <Form
  248.             className="edit-form"
  249.             onSubmit={() => console.log("Submitting filter form")}
  250.           >
  251.             <Row>
  252.               {mainFilters.map(
  253.                 ({
  254.                   name,
  255.                   optionSelector,
  256.                   selected,
  257.                   disabledSelector,
  258.                   loadingMessage,
  259.                   noOptionsMessage
  260.                 }) => (
  261.                   <Col lg={3} key={name}>
  262.                     <Form.Group controlId={name} key={name}>
  263.                       <CustomSelect
  264.                         name={name}
  265.                         options={state[optionSelector]}
  266.                         selected={state[selected]}
  267.                         onChange={value =>
  268.                           setState(prevState => ({
  269.                             ...prevState,
  270.                             [selected]: value
  271.                           }))
  272.                         }
  273.                         request={() => console.log("Reading csv file...")}
  274.                         isDisabled={
  275.                           disabledSelector ? !state[disabledSelector] : false
  276.                         }
  277.                         isLoading={false}
  278.                         loadingMessage={loadingMessage}
  279.                         noOptionsMessage={noOptionsMessage}
  280.                       />
  281.                     </Form.Group>
  282.                   </Col>
  283.                 )
  284.               )}
  285.             </Row>
  286.           </Form>
  287.         </Col>
  288.  
  289.         <Col xs={12}>
  290.           <h5 className="mt-2">
  291.             GESCHIKTE KABELS <small>(149 resultaten)</small>
  292.           </h5>
  293.  
  294.           <PaginationProvider pagination={paginationFactory({ custom: true })}>
  295.             {({ paginationProps, paginationTableProps }) => (
  296.               <BootstrapTable
  297.                 rowStyle={(row, rowIndex) =>
  298.                   rowIndex % 2 === 0
  299.                     ? { backgroundColor: "white" }
  300.                     : { backgroundColor: "#F4F4F4" }
  301.                 }
  302.                 noDataIndication={<p>Geen kabels gevonden</p>}
  303.                 bootstrap4
  304.                 keyField="id"
  305.                 data={products}
  306.                 columns={columns}
  307.                 pagination={paginationFactory()}
  308.                 bordered={false}
  309.                 wrapperClasses="table-responsive"
  310.               />
  311.             )}
  312.           </PaginationProvider>
  313.         </Col>
  314.       </Row>
  315.     </Container>
  316.   );
  317. };
  318.  
  319. export default Home;
Advertisement
Add Comment
Please, Sign In to add comment