Display your CSV file in an interactive DataView in three steps:
- Upload a CSV to your site
- Pass the CSV absolute path to DataKit SDK
- Embed a shortcode.
Demo of displaying a CSV in a table
We have a CSV file of Oscar winners for Best Actor through 2024. We uploaded it to the site and rendered it with DataKit SDK:
It just took a few lines of code:
PHP
$csv_data_source = new CsvDataSource( '[file path]/oscar-example-data.csv' );
$oscar_winner_best_actor = DataView::table(
'csv-demo',
$csv_data_source,
[
TextField::create( 1, 'Year' ),
TextField::create( 2, 'Age' ),
TextField::create( 3, 'Name' ),
TextField::create( 4, 'Movie' ),
],
Sort::desc( 'Year' )
)->paginate( 10 );
do_action( 'datakit/dataview/register', $oscar_winner_best_actor );
Your CSV that you’re trying to display? Similarly easy with DataKit.