Rich Ajax Application Framework

CSV To HTML Table

Converts a CSV datasource into an HTML using the Table Plugin



PHP Source:
<?php

require_once('raxan/pdi/autostart.php');

Raxan::loadPlugin('plugins/table.php', true);

class MyPage extends RaxanWebPage {

    protected function _load() {
        $this->title('Table Plugin Demo');

        $data = Raxan::importCSV('addressbook.csv');

        $btn = $this['<a id="btnhide" />']->appendTo('body');
        $btn->text('Toggle Address Column');
        $hidecolumn = isset($_GET['toggle']) ? true : false;
        $btn->attr('href','csv-table.php'.(!$hidecolumn ? '?toggle=1': ''));

        $tbl =  new Table();
        $tbl->addColumn('name','Name');
        if (!$hidecolumn) $tbl->addColumn('address','Address');
        $tbl->addColumn('country','Country');
        $tbl->dataSource($data);
        $tbl->appendTo('body'); // append to the body tag
        $this->tbl = $tbl;

    }

}


?>

Plugin Source:

HTML Source:

Data Source (addressbook.csv):
name,address,country
Mark,12 Bridge Walk Ave,USA
Mary,34 Kingsman Drive,UK
Jane,56 Internet Drive,JM
Pam,12 Computer Highway,USA
Kim,120 Memory Lane,UK