项目作者: Grace951

项目描述 :
simple react sortable searchable table
高级语言: JavaScript
项目地址: git://github.com/Grace951/react-table.git
创建时间: 2016-12-18T05:15:05Z
项目社区:https://github.com/Grace951/react-table

开源协议:MIT License

下载


react-sort-search-table

npm version
Download Count

demo png

  • with fontawesome
  • Searchable
  • Sortable
  • Pager Include
  • Use your Custom Component to Render Specific TD
  • react >= 16.8.2
  • react-dom >= 16.8.2

Live Demo

Live demo: https://grace951.github.io/react-table/

Example

Need more example? See examples

  1. Include fontawesome
  1. <link
  2. rel="stylesheet"
  3. href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css"
  4. />
  5. <script src="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/js/all.min.js"></script>
  1. Use the component
  1. let MyData = [
  2. {
  3. cat: 1,
  4. _id: "d-rhe-428-j",
  5. imageUrl: "img/products/rhe-428-j.png",
  6. name: "RHE-428-J (4ch Compact)",
  7. brand: "iCATCH",
  8. type: "HD-SDI",
  9. channel: 4,
  10. remote: "LAN, ie, iPhone, iPad, Android, 3G mobile",
  11. backup: "USB, Network",
  12. videoout: "HDMI, VGA",
  13. },
  14. {
  15. cat: 1,
  16. _id: "srd-482",
  17. imageUrl: "img/products/srd-482-2.jpg",
  18. name: "SRD-482 (4ch)",
  19. brand: "Samsung",
  20. type: "HD-SDI",
  21. channel: 4,
  22. remote: "LAN, ie, iPhone, iPad, Android, 3G mobile",
  23. backup: "USB, Network",
  24. videoout: "HDMI, VGA",
  25. },
  26. {
  27. cat: 1,
  28. _id: "sh3-04u",
  29. imageUrl: "img/products/sh3-04u-1.png",
  30. name: "SH3-04U (4ch)",
  31. brand: "SNM",
  32. type: "HD-SDI",
  33. channel: 4,
  34. remote: "LAN, ie, iPhone, iPad, Android, 3G mobile",
  35. backup: "USB, Network",
  36. videoout: "HDMI, VGA, BNC",
  37. },
  38. {
  39. cat: 1,
  40. _id: "d-rhe-828-j",
  41. imageUrl: "img/products/rhe-828-j.png",
  42. name: "RHE-828-J (8ch Compact)",
  43. brand: "iCATCH",
  44. type: "HD-SDI",
  45. channel: 8,
  46. remote: "LAN, ie, iPhone, iPad, Android, 3G mobile",
  47. backup: "Network, USB 2.0 or SATA",
  48. videoout: "HDMI, VGA, BNC",
  49. },
  50. ];
  51. class BaseProductDeleteComponent extends React.Component {
  52. constructor(props) {
  53. super(props);
  54. this.deleteItem = this.deleteItem.bind(this);
  55. }
  56. deleteItem() {
  57. alert("delete " + this.props.rowData.name);
  58. console.log(this.props.rowData, this.props.tdData);
  59. }
  60. render() {
  61. return (
  62. <td>
  63. <input
  64. type="button"
  65. className="btn btn-danger"
  66. value="Delete"
  67. onClick={this.deleteItem}
  68. />
  69. </td>
  70. );
  71. }
  72. }
  73. function ProductTblImgpreloader() {
  74. return <div className="loading-div" style={{ minHeight: "100px" }} ></div>;
  75. }
  76. const TblImageLoader = (props) => (
  77. <ImageLoader
  78. src={props.data}
  79. wrapper={React.DOM.div}
  80. preloader={ProductTblImgpreloader}
  81. >
  82. NOT FOUND
  83. </ImageLoader>
  84. );
  85. const BaseProductTblImageComponent = (props) => {
  86. return (
  87. <td
  88. style={{
  89. width: "170px",
  90. minWidth: "170px",
  91. backgroundColor: "#fff",
  92. }}
  93. >
  94. <a href={props.rowData.imageUrl} target="_blank">
  95. <TblImageLoader data={props.rowData.imageUrl} ></TblImageLoader>
  96. </a>
  97. </td>
  98. );
  99. };
  100. class BaseProductEditComponent extends React.Component {
  101. constructor(props) {
  102. super(props);
  103. this.editItem = this.editItem.bind(this);
  104. }
  105. editItem() {
  106. alert("edit " + this.props.rowData.name);
  107. console.log(this.props.rowData, this.props.tdData);
  108. }
  109. render() {
  110. return (
  111. <td>
  112. <input
  113. type="button"
  114. className="btn btn-warning"
  115. value="Edit"
  116. onClick={this.editItem}
  117. />
  118. </td>
  119. );
  120. }
  121. }
  122. const ProductsTblPage = (props) => {
  123. let col = [
  124. "imageUrl",
  125. "name",
  126. "brand",
  127. "type",
  128. "channel",
  129. "remote",
  130. "backup",
  131. "HDD",
  132. "videoout",
  133. "delete",
  134. "edit",
  135. ];
  136. let tHead = [
  137. "Image",
  138. "Model",
  139. "Brand",
  140. "Type",
  141. "Channel",
  142. "Remote",
  143. "Backup",
  144. "HDD",
  145. "Video output",
  146. "Delete",
  147. "Edit",
  148. ];
  149. return (
  150. <SortableTbl
  151. tblData={MyData}
  152. tHead={tHead}
  153. customTd={[
  154. { custd: BaseProductTblImageComponent, keyItem: "imageUrl" },
  155. { custd: BaseProductEditComponent, keyItem: "edit" },
  156. { custd: BaseProductDeleteComponent, keyItem: "delete" },
  157. ]}
  158. dKey={col}
  159. ></SortableTbl>
  160. );
  161. };
  162. ProductsTblPage.propTypes = {};
  163. ReactDOM.render(<ProductsTblPage ></ProductsTblPage>, document.getElementById("app"));

Props

  • tblData: Array
    • Source data of Table
  • tHead: Array
    • Table header to be displayed
  • paging: boolean, default true
    • show pagine or not
  • search: boolean, default true
    • show search bar or not
  • defaultCSS: boolean, default true
    • Use Default CSS or not
  • customTd: Array
    • Use your Custom Component to Render Specific TD
    • The Custom Component will received 3 props
      • tdData
        • the data corresponds to this column
      • rowData
        • the data array corresponds to this row
      • field
        • the key of data array
  • dKey: Array
    • Table column to be displayed

Notes

  • Feel free to contribute and/or provide feedback!

Build the example locally

  1. git clone https://github.com/Grace951/react-table.git
  2. cd example/example2
  3. npm install
  4. npm run dev

Then open localhost:3100 in a browser.

License

MIT