Sunday, December 21, 2014

A React Data Table

This blog is about a web based data table written with Facebook React. Facebook React is a cool and fun way to create reusable UI components for the web using javascript. It lets the programmer focus on writing code on how to render the UI, give it state and leaves DOM manipulation to the framework. If you haven't used it yet, here's a very good guide on getting started with it.

If you're already familiar with React and you need to write a Data Table component but have no time, please feel free to use and modify the one that I've written.

Screen Shots:


With expand/collapse row enabled:



Click Here for the Working Demo.

Click Here for the Source Code.

Sample Snippet on how to use the data table: (Complete examples - JSX and  non JSX codes)
  1. ...
  2. <script type="text/jsx">
  3. var selectItemHandler = function(o) {
  4. // Row selection handler here
  5. };
  6. var locationRenderCallback = function(data) {
  7. ...
  8. };
  9. var colDef = [{title:"Area Name", key:"areaName"},
  10. {title:"Property Type", key:"propertyType"},
  11. {title:"Property Name", key:"propertyName"},
  12. {title:"Address", key:"addr"},
  13. {title:"Zip Code", key:"zip"},
  14. {title:"Phone Number", key:"phone"},
  15. {title:"Management Company", key:"mgmtCompany"},
  16. {title:"Units", key:"units"},
  17. {title:"Location", key:"loc", renderCallback:locationRenderCallback, sortable:false},
  18. {key:"lat", isVisible:false},
  19. {key:"lon", isVisible:false}];
  20. var renderExpandedRowContent = function(data) {
  21. return <PicGallery title="Street view of the area..."
  22. lat={data.lat}
  23. lon={data.lon}/>;
  24. };
  25. React.render(<RDataTable colDefinitions={colDef}
  26. data={sampleJson}
  27. selectItemCallback={selectItemHandler}
  28. enableExpandCollapseRow={true}
  29. renderExpandedRowContent={renderExpandedRowContent}/>,
  30. document.getElementById("table-container”));
  31. </script>
  32. ...
  33. <div id="table-container" class="table-container"></div>