Was this page helpful?

Displaying a CSV file as a Table

    Introduction

     Although this template does not yet display native excel files within a page you can export those excel files to csv text files and have them shown with this template.  I am still working out some of the options (the original documentation is in japanese) but it works rather well right now so I decided to release it. 

    History

    Version Date Author Description
    1.0 09/23/2009 rberinger Initial Release

    Requirements

    • This template requires MindTouch version: This has only been tested on MindTouch Core (Lyons)

    How do I install it?

    1. Create a template, call it "Template:TemplateName" (or rename as you desire).  You must have UNSAFECONTENT permission for this to work.
    2. Create a "DekiScript" block on the template page (use the "Style" menu in the editor")
    3. Copy the code from the end of this page and paste it into the DekiScript block.  To copy, click "expand source", then mouse over the top right corner of the source code, and click the "view source" button.  This will pop up a window with the source code.  Select all, then copy to clipboard.
    4. Make sure there isn't an extra blank paragraph after the DekiScript block! Do this every time you edit!!!  
    5. Save.
    6. Download the .js and image files from this page and save on a page in your wiki.
    7. Prior to uploading the .js file on your wiki open it up in a text editor and update the image icon links.

    Find these lines in the .js file:

            loadImg  : (new Image()).src='http://192.168.10.102/@api/deki/file...n-loadinfo.gif',  //Dafault loading IMG
            sortNImg : (new Image()).src='http://192.168.10.102/@api/deki/files/16/=icon-n.gif',         //Dafault sort IMG N
            sortDImg : (new Image()).src='http://192.168.10.102/@api/deki/file...on-d-green.gif',   //Dafault sort IMG D
            sortAImg : (new Image()).src='http://192.168.10.102/@api/deki/file...on-a-green.gif',   //Dafault sort IMG A

    And update the uri's to point to your image icon files.

     Then upload to your wiki.  You can continue to reference the ones on this page but it could be moved or deleted at anytime.  Its usually safer and faster from your own.

    A quick note about the examples on this page

    For all the examples on this page, the code is shown before the working example.  The code is shown with the syntax extension, and looks like this:

    csv2Table{fileuri: str, maxheight: str, maxwidth: str, sortable: bool};

    This means that the actual code on the page should be enclosed in a DekiScript block.  If you want to copy the code from this page, then use the same procedure as described in steps 2-4 above. 

    How do I use it?

    See Examples:

    Arguments

    Name
    Type
    Default
    Description
     fileuri str n/a URI to the csv file to display as a table
     maxheight str n/a Max height before Horizontal Scroll bars are used
     maxwidth str 100% Max width before Vertical Scroll bars are used
     sortable bool true Enable or disable sorting (recommended if using another table formating template)

    Examples

     In a DekiScript Block:  This will load the selected file into a table on this page, sorting is enabled by default.

    csv2Table{fileuri: 'http://developer.mindtouch.com/@api/deki/files/4826/=Export_Sales_Info-demo.csv', maxheight: '400px' };
    

     

    In a DekiScript Block:  This will load the selected file into a table on this page, sorting is not enabled for this file.

    csv2Table{fileuri: 'http://developer.mindtouch.com/@api/deki/files/4827/=DMI_house_09-23-2009.csv', maxheight: '400px', sortable: false };
    

     

    Reference(s)

    Direct all questions, comments, or discussion to this forum thread.

    Credits/Special Thanks

     Special thanks to the original author of the csv2Table jQuery function: 'Toshiro Takahashi'

    Template/Extension Source Code

    var id = string.replace(json.emit(@id),'\"','');
    var fileuri = ($fileuri ?? $0 ?? '');
    var maxheight = ($maxheight ?? $1 ?? '');
    var maxwidth = ($maxwidth ?? $2 ?? '100%');
    var sortable = ($sortable ?? $3 ?? true);
    
    let sortable = {sortable: (sortable) };
    
    <html><head>
        <script type="text/javascript" src="http://developer.mindtouch.com/@api/deki/files/4825/=jquery.csv2table-0.02-b-2.8.js" />
        <script>"
        $(document).ready(function(){
          $('#"..id.."').csv2table('"..fileuri.."', "..json.emit(sortable)..");
        });
        "</script>
        <style type="text/css">"
            #"..id.." {width:"..maxwidth..";height:"..maxheight..";overflow:auto;white-space:nowrap;}
        "</style>
    </head>
    </html>
    <div id=(id)></div>
     

     

    Disclaimers

    Release under public domain.

    Was this page helpful?
    Tag page

    Files 7

    FileVersionSizeModified 
    Viewing 9 of 9 comments: view all
    Thanks for this script - it looks terrific. One problem I am having:
    (unable to fetch text document from uri [status: 401 (Unauthorized)])
    My csv is there, the script and the images are in place, and I have unsafe content allowed.

    Do I need to send login creds with my request? and if so, how?

    thanks!
    Posted 09:55, 11 Dec 2009
    You should not have to send in the credentials if you have access to the page itself. If this is not the case please let me know by posting to the forum page with an example of the template call your using and an excerpt of the file if its not confidential.
    Posted 10:39, 11 Dec 2009
    <div style="max-height:400px;overflow:auto">
    var uri = 'http://dev.ii4sm.zz:8989/@api/deki/files/2094/=Book1.csv';
    var csv = string.splitcsv(web.text(uri)).values;
    TsTable { columns:csv[0], data:list.splice(csv,0,1) };
    </div>


    results an empty table being rendered with the following in the header and first row:

    (unable to fetch text document from uri [status: 401 (Unauthorized)])
    (no data)
    Posted 15:57, 11 Dec 2009
    BTW here's the file

    Work Item:,Cumulative amount @ end of this RC†,Target portion to be compl this RC†,% Complete for this RC (actual),Owner,As at:
    UC/Component/Service/other,,,,,
    UC x,0.4,0.2,100,MBB,dd-mon-yyyy
    UC y,0.1,0.1,60,PN,† dd-mon-yyyy
    SVC a,0.7,0.5,80,AH,dd-mon-yyyy
    CM k,1,0.2,90†,JH,dd-mon-yyyy
    ,,,,,
    ,,,,,
    ,,,,,
    ,,,,,
    Posted 16:00, 11 Dec 2009
    Hi Team, I am getting the same error as imattdotnet. I've create the page and uploaded the file so I assume I do have access to it. Any idea h9ow to fix this problem?

    Thanks
    Posted 12:34, 13 Jan 2010
    @imattdonnet, @Tonio_lora: TSTable is a different template. There should be no need for string.splitcsv or list.spliceing with this template.
    Posted 13:05, 13 Jan 2010
    The script works perfectly, however I'm accessing a CSV with close to 6000 rows and it takes a while to process. Firefox prompts me that the script has stopped responding, I continue through the error and it displays the table fine. Any thoughts on how to speed up the processing?
    Posted 09:29, 4 Oct 2010
    I've been trying to make it so only certain table columns in csv2table are sortable, any suggestions?
    Posted 05:52, 23 May 2011
    This is great any possibility of a search function on the top?
    Posted 11:15, 1 Sep 2011
    Viewing 9 of 9 comments: view all
    You must login to post a comment.

    Copyright © 2011 MindTouch, Inc. Powered by