Note that there are some explanatory texts on larger screens.

plurals
  1. POGenerating autosorted HTML tables from text file?
    primarykey
    data
    text
    <p><strong>Update</strong></p> <p>So I managed to get my table generated using <a href="https://stackoverflow.com/questions/4667816/generating-autosorted-html-tables-from-text-file/4667994#4667994">gabel's</a> suggestion with a few minor issues.</p> <p>This was especially useful since my colleague only has to edit a .CSV file in Excel.</p> <p>Due to presentation reasons, she now wants the table to look like so:</p> <pre><code>------------------------------ | FRUITS | VEGGIES | ------------------------------ | Banana | Potato | ------------------------------ | Cherry | Pumpkin | ------------------------------ | Orange | Okra | ------------------------------ | MEATS | CARBS | ------------------------------ | Chicken | Bread | ------------------------------ | Beef | Rice | ------------------------------ | Pork | | ------------------------------ </code></pre> <p>There are two <code>thead</code> entries or perhaps two tables but the .CSV file would still be:</p> <pre><code>FRUITS,VEGGIES,MEATS,CARBS Banana,Potato,Chicken,Bread ... </code></pre> <p><strong>Questions</strong></p> <ol> <li>How would I parse the CSV file that it would break after the second comma and then create a new table or a new header/body set within the same table?</li> </ol> <hr> <p>There's a HTML table I'd like to have generated with as little work possible for the person actually filling in the data. </p> <p>The table looks like this (proxy example):</p> <pre><code>------------------------------ | FRUITS | VEGGIES | ------------------------------ | Banana | Potato | ------------------------------ | Cherry | Pumpkin | ------------------------------ | Orange | Okra | ------------------------------ </code></pre> <p>Currently, the table is done in standard HTML and I'm using CSS and jQuery to give it specific colours and 'zebra'-striping, respectively. The alphabetical sorting has been done manually.</p> <p>However, with the code set in place the person I'm handing it over to does not want to edit the HTML. She'd rather edit some text file where she can write/edit (this was just a suggestion from a friend):</p> <pre><code>{Banana: Fruit, Potato: Veggies, Okra: Veggies... } </code></pre> <p>The Javascript should then pick up this source file, generate a table where the individual columns are automatically sorted alphabetically and then zebra-striped using the CSS layout.</p> <p><strong>Questions</strong></p> <ol> <li>I've got the jQuery plug-in. What else would I need to actually generate the tables? </li> <li>Would you recommend using the above dictionary structure for the source file or perhaps a CSV file?</li> <li>For the sake of argument, happens when I face the scenario of <code>{Tomato: Fruit, Tomato: Veggies...}</code>. Is there a workaround for this case?</li> </ol> <p>This may seem like overkill, but it's something I need to get done.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload