custom_formattingNew! A list of column indexes and custom functions to format your data (see below)
Custom formatting
If you want to do custom formatting for one or more column, you can pass in an array of arrays containing the index of the column and a custom function for formatting it. You can pass in multiple formatters and they will be executed in order.
The custom functions must take in one parameter (the value in the cell) and return a HTML string:
Example:
<script>//my custom function that creates a hyperlinkfunctionformat_link(link){if(link)return"<a href='"+link+"' target='_blank'>"+link+"</a>";elsereturn"";}//initializing the tableCsvToHtmlTable.init({csv_path: 'data/Health Clinics in Chicago.csv',element: 'table-container',allow_download: true,csv_options: {separator: ',',delimiter: '"'},datatables_options: {"paging": false},custom_formatting: [[4,format_link]]//execute the function on the 4th column of every row});</script>
Note that you should take care about HTML escaping to avoid XSS or broken layout.
jQuery has a nice function text() which safely escapes HTML from value.
4. Run it
You can run this locally using this handy python command:
GitHub pages You can host your table on GitHub pages for free! Once you've made all your changes and committed them, push everything in the master branch to gh-pages which automatically enables GitHub pages.
Web server This project should work on any web server. Upload this entire project (including all the css, data, fonts and js folders) to a public folder on your server using FTP.
6. iframe it (optional)
Want to embed your nifty table on your website? You can use an iframe. Once you've deployed your table (above in step 5) you can link to it in an iframe right in your HTML.
请发表评论