Skip to content
This repository has been archived by the owner on May 25, 2018. It is now read-only.

Commit

Permalink
Readme enhancements.
Browse files Browse the repository at this point in the history
 + info on serialization added
 + screenshot from demo page added
  • Loading branch information
reednj committed Aug 28, 2011
1 parent dfebc00 commit 8fad4a5
Showing 1 changed file with 47 additions and 10 deletions.
57 changes: 47 additions & 10 deletions README.md
@@ -1,39 +1,42 @@
jsTable
============
jsTable is a mootools control designed to make it easy to add data tables to the page with javascript. It is designed to be very easy to
serialize in order to send the data to the server.
jsTable is a mootools control designed to make it easy to add serializable data tables to the page with javascript.

![ScreenShot](http://)
![ScreenShot](http://i.imgur.com/b2hU0.png)

Demo
-----
See [this page](http://popacular.com/jstable/Test/demo.html) for a demo of jsTable in action.

Usage
------

(This is only a summary. Please see the documentation for a method by method description of usage)
(This is only a summary. Please see [the documentation](https://github.com/reednj/jsTable/blob/master/Docs/jsTable.md) for a method by method description of usage)

If we have a div object in the html that looks like this:

<div id='new-table'></div>
<div id='new-table'></div>

It can be turned into a jsTable by constructing the object and passing the element as a parameter.

var jst = new jsTable('new-table');

Then we add some columns to the table:

// usage: addColumn(column_name, column_description);
jst.addColumn('filename', 'File Name');
jst.addColumn('size'); // if the description is not given, the column name is used instead

Now data can be added to the table. Elements can be added, as well simple strings and html.

// usage: addRow(column1, column2, ...)
jst.addRow('test.txt', '12kb');

You can get and set the contents of the cells using the setCell, getCell functions

var contents = jst.getCell(row_index, column_name);
jst.setCell(row_index, column_name, contents);

You can serialize the table to a javascript object, or to a json string using the methods toJson and toData respectively.

Styling
-------

Expand All @@ -45,14 +48,48 @@ following.
}

The column names are applied to the table cells as css classes and can be used also. The class names are prefixed with 'jst-'

/* hide the 'size' column */
#new-table td.jst-size, #new-table th.jst-size {
display: none;
}

These classes can also be used to set borders, font sizes, padding etc.

Serialization
-------------

You can serialize the table to a javascript object, or to a json string using the methods toJson and toData respectively.

// set up a table with two columns
jst = addTable('new-table);
jst.addColumn('n1');
jst.addColumn('n2');

// add some rows to the table
jst.addRow(10, 20);
jst.addRow(30, 40);

You would get html that looks a bit like this:

<table>
<tr><td class='jst-n1'>10</td> <td class='jst-n2'>20</td></tr>
<tr><td class='jst-n1'>30</td> <td class='jst-n2'>40</td></tr>
</table>

Using the toJson method would serialize it this:

// jst.toJson();
[
{'n1':10, 'n2':20},
{'n1':30, 'n2':40}
]

You can also serialize just a single column:

//result from jst.toJson('n1');
[10, 30]

Use Inheritence for Custom Tables
---------------------------------

Expand All @@ -63,9 +100,9 @@ Such a class would look something like this:
var FileTable = new Class({
Extends: jsTable,
initialize: function(element, options) {

this.addColumn('filename', 'File Name');
this.addColumn('size');

}
}
});

0 comments on commit 8fad4a5

Please sign in to comment.