News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

Table From CSV

Started by Anguz, October 27, 2004, 06:34:53 AM

Previous topic - Next topic

Elijah Bliss

Quote from: Elijah Bliss on December 05, 2004, 06:34:41 PM
Quote from: Anguz on December 05, 2004, 06:20:46 PM
There's a javascript file added to your default theme dir during install. If you're using another theme, you need to make a copy of the file to that theme's dir as well.

The "sorttable.js" is located in the theme I am using.

The problem I am encountering is this:
if I just have this for example:
[table=]Giants,Forty Niners,Bears[/table]

the sortable links show up in the headers, but as soon as I make a carriage return,
[table=]Giants,Forty Niners,Bears
Bonds,Young,Arrington[/table]

the links in the headers go dead.

I got it to work by changing this line of code from the mod:

From:
$arr1[] = '~\[table=(.*?)\](.*?<br />)?(.*?)\[/table\](?:\s|\xA0|<br />|&nbsp;)?~ie';

To:
$arr1[] = '~\[table=(.*?)\](.*?<br>)?(.*?)\[/table\](?:\s|\xA0|<br>|&nbsp;)?~ie';

I don't know why that made a difference, but nonetheless, great mod, and kudos designing mods that don't interfere with the mods from the other mod developers. Great work!

Anguz

Thank you. Glad you find them useful. :)

On the modification you made, break tags will always be <br /> and not <br>.

I didn't fully understand what was the problem you were having. If you only have one row in the table, it should not have the links to sort it, if it has more than one, the first row will be the headers for the columns.
Cristián Lávaque http://cristianlavaque.com

Anguz

I rewrote the code, could you try this and tell me if it solves your problem?


// Table from CSV. [table=]cell1,cell2[/table]
if(isset($add['[table='])){
$arr1[] = '~\[table=(.*?)\](.*?)\[/table\](?:\s|\xA0|<br />|&nbsp;)?~ie';
$arr2[] = 'parse_table_csv(\'$1\', \'$2\')';
}



function parse_table_csv($comma, $table)
{
static $id = 1;
$comma = empty($comma) ? ',' : $comma;
$ths = $tds = '';
$table = trim(strtr($table, array('<br />' => "\n")));
if (strpos($table, "\n") !== false)
{
$table = explode("\n", $table);
$ths = '<tr><th>' . strtr(array_shift($table), array($comma => '</th><th>')) . '</th></tr>';
$table = implode('</td></tr><tr><td>', $table);
}
$tds = '<tr><td valign="top">' . strtr($table, array($comma => '</td><td valign="top">')) . '</td></tr>';
return '<table id="tbl' . $id++ . '"' . (!empty($ths) ? ' class="sortable"' : '') . '>' . $ths . $tds . '</table>';
}


It fixes a problem where it wouldn't parse right if there were two CSV tables in the same message and the first one consisted of only one line.
Cristián Lávaque http://cristianlavaque.com

Elijah Bliss

Quote from: Anguz on December 06, 2004, 03:44:28 AM
I rewrote the code, could you try this and tell me if it solves your problem?


// Table from CSV. [table=]cell1,cell2[/table]
if(isset($add['[table='])){
$arr1[] = '~\[table=(.*?)\](.*?)\[/table\](?:\s|\xA0|<br />| )?~ie';
$arr2[] = 'parse_table_csv(\'$1\', \'$2\')';
}



function parse_table_csv($comma, $table)
{
static $id = 1;
$comma = empty($comma) ? ',' : $comma;
$ths = $tds = '';
$table = trim(strtr($table, array('<br />' => "\n")));
if (strpos($table, "\n") !== false)
{
$table = explode("\n", $table);
$ths = '<tr><th>' . strtr(array_shift($table), array($comma => '</th><th>')) . '</th></tr>';
$table = implode('</td></tr><tr><td>', $table);
}
$tds = '<tr><td valign="top">' . strtr($table, array($comma => '</td><td valign="top">')) . '</td></tr>';
return '<table id="tbl' . $id++ . '"' . (!empty($ths) ? ' class="sortable"' : '') . '>' . $ths . $tds . '</table>';
}


It fixes a problem where it wouldn't parse right if there were two CSV tables in the same message and the first one consisted of only one line.

Do I add this code before, after or replace?

Anguz

QuoteDo I add this code before, after or replace?

Replace. It won't be hard to find what they replace, look for the comment in the first block and for the function name in the second one.
Cristián Lávaque http://cristianlavaque.com

Elijah Bliss

Quote from: Anguz on December 06, 2004, 05:11:51 AM
QuoteDo I add this code before, after or replace?

Replace. It won't be hard to find what they replace, look for the comment in the first block and for the function name in the second one.

After replacing the code I get a blank white screen when I try to go to the message index.

Anguz

Odd, it's working okay for me, you probably missed something in the replace? Anyway, the update for SMF 1.0 will be out soon, when that version gets released. In the meantime you can use what you had working. :)
Cristián Lávaque http://cristianlavaque.com

1948Pal

Hi.
Does each of these versions complement the previous one, as in the faster parse code, or each version should replace its predecessor?
"No matter how long the river, the river will reach the sea".
Eugene Fitch Ware

Anguz

Quote from: 1948Pal on December 13, 2004, 04:10:13 PM
Hi.
Does each of these versions complement the previous one, as in the faster parse code, or each version should replace its predecessor?

The 1.11 version is complete, it doesn't go on top of the previous one. If you have an earlier one installed, uninstall it first and then install 1.11. :)
Cristián Lávaque http://cristianlavaque.com

Anguz

1.12


  • Updated for SMF 1.0.1
Cristián Lávaque http://cristianlavaque.com

johnm

does this only sort the first colum?

cause if i try to sort the second/third/etc colum i get an error on the page and it does nothing?

Anguz

It should work with every column. Could you post a little example of a table that does that for you?
Cristián Lávaque http://cristianlavaque.com

Tony Reid

Thanks for this anguz,

We use tables on our site and this will be a great help :)

Tony Reid

Anguz

Quote from: Tony on February 01, 2005, 04:28:23 AM
Thanks for this anguz,

We use tables on our site and this will be a great help :)

You're welcome. I'm really glad you find it useful. ;)
Cristián Lávaque http://cristianlavaque.com

Tony Reid

I would like to expand the columns, as its a little cramped - and I dont think CSS will do it quite like I would like.

Could you tell me how to increase the column width by say.... 5 spaces?

Thanks,
Tony.

Tony Reid

Anguz

Did you try adding five spaces to one of the values in that column?
Cristián Lávaque http://cristianlavaque.com

Tony Reid

Oops.... my fault :( all fixed ;D

Thanks again,
Tony
Tony Reid

FaSan

Quote from: John on January 30, 2005, 12:40:16 PM
does this only sort the first colum?

cause if i try to sort the second/third/etc colum i get an error on the page and it does nothing?


I've the same problem ..

Anguz

Quote from: Anguz on January 30, 2005, 08:13:48 PM
It should work with every column. Could you post a little example of a table that does that for you?
Cristián Lávaque http://cristianlavaque.com

FaSan

this is an example :

[table=]Numero,Nome,Città
000.1234567,PokeMone,Bologna
987.7654321,Longinus,Firenze
<br>,<br>,<br>
01234567890, Fear°, Roma
<br>, <br>, <br>[/table]




FaSan

Advertisement: