Taking data from a CSV file and displaying it in a table using asset listing


(David Avery) #1

Hi all, I'm trying to implement an asset list that lists values in a table taken from a CSV Datasource using asset listing. I've been following this tutorial (http://forums.squizsuite.net/index.php?showtopic=11377), and have already messaged the creator, but thought you guys may have some insights to help me too, as he is Australian and has probably gone to bed for the night :) I can't find much more info on creating tables populated by asset lists, and unfortunately, this tutorial isn't working for me. When I search from the books publish year I get the sites standard 404 page. If anyone requires any more info to try and help me, don't hesitate to ask :) Many thanks, David


(David Avery) #2

I'm trying to get this code (Found from trawling the forums) http://jsfiddle.net/4mujX/ to work with the keyword %asset_listing% to fill in the table, as shown in the code below. function drawVisualization() { // Create and populate the data table. var data = google.visualization.arrayToDataTable([ ['Name', 'Phone', 'Suburb', 'Class', 'Location'], %asset_listing% ['' , '', '', '', ''] ]);

  // Create and draw the visualization.
  visualization = new google.visualization.Table(document.getElementById('table'));
  visualization.draw(data, null);
}


google.setOnLoadCallback(drawVisualization);
</script>

<div id="table"></div>

I've tested, and the code works without %asset_listing% I've formatted the asset listing so it produces data from my CSV file in the format

 

['%ds__book_title%', '%ds__publish_year%', '%ds__publisher%', '%ds__author%', '%ds_isbn%'],

 

and when only the %asset_listing% keyword is placed into the page content

 

 ['a', '20/06/1905', 'Penguin', 'Dave', ''], ['b', '14/06/1905', 'Penguin', 'Dave', ''], ['c', '05/07/1905', 'Penguin', 'Dave', ''], ['d', '04/07/1905', 'Penguin', 'Mat', ''], ['e', '18/05/1905', 'Penguin', 'Mat', ''], ['f', '06/06/1905', 'Penguin', 'Mat', ''], ['g', '29/05/1905', 'Penguin', 'Keven', ''],

 

is produced on the page. Any help to get this to work would be very much appreciated!

 

Cheers,

 

Dave


(Nic Hubbard) #3

Have you looked at the Column Layout screen of the Asset Listing? You can use this to create a table of data from an asset listing.


(David Avery) #4

Hi Nic, could you give me some advice as to how this would work? I can set the amount of columns to 5, but I'm unsure of how to set the data into the tables. Each asset being listed has 5 pieces of data, the title, year of publish, author, publisher and ISBN. Do you know how I could map this data to the correct columns?

 

Many thanks, as always,

 

David


(David Avery) #5

Hi Nic, again... :P

 

I've created this code which puts my information into a table:

 

Asset listing Page Contents code:

%asset_listing%

Asset listing default format code:

%asset_listing%

For some reason, the ISBN doesn't actually get inputted into the table, even though I can look at each individual shadow asset and make sure each of them has an ISBN number taken from the CSV. Any reasons why this may be happening? (It's a 4 digit number).

 

If you know also how to do it your way that would be great!

 

Many thanks.


(Tom Chadwin) #6

The keyword is missing an underscore - these shorthand ones have a double one.


(David Avery) #7

Cheers Tom, I copied and pasted them all, but it hasn't picked that extra one up.


(Nic Hubbard) #8

I think doing it the way you are will be best. Using the Column Layout is going to print one asset per cell, so I don't think you will get the results you were wanting.


(David Avery) #9

I think you're right, as I did try your idea, and it simply listed all 5 columns of a row of the CSV in a single cell. And then just replicated that for each shadow asset.