Skip to content
Andrew Plummer edited this page May 21, 2017 · 2 revisions

When I edit the table fields, they don't update automatically even though if I refresh the page the data has changed. What gives?

This is a common problem that is easily solved by making sure that the PHP constructor (i.e. new TableGear()) comes before any HTML or other character data in your PHP document. Any HTML that comes before that line will get mixed into the JSON output, which will cause a Javascript error on update.

Note: To alleviate any confusion, this is the PHP constructor that must come before any output. The Javascript constructor you can place anywhere in the page (after the table).

Can't I add new rows?

This feature was added as of 1.5.2 you can.

How do I suppress the warning messages that appear?

PHP can sometimes display warning messages depending on the configuration of your server. These are just warnings, and not indications of errors in the code. To turn them off, simply add the following line before you invoke TableGear:

error_reporting(E_ERROR);

If you need to, you can turn on more strict error reporting after TableGear has finished processing.

How do I limit visible columns?

The "columns" parameter of the "database" object will allow you to limit columns. You must pass it an array of the columns you want to show:

"database" => array(..."columns" => array("ONE", "TWO", "THREE)...)

How do I limit visible rows?

Limiting rows is a much more case-by-case problem, and exactly what SQL was designed for — so this is the perfect job for a custom query. Simply call the "fetchDataArray" method on the TableGear object and pass in the SQL for your query:

$tg->fetchDataArray("SELECT * FROM table WHERE price < 2 LIMIT 10");

One caveat: you must set your database primary key field in the "database" parameter of the constructor or functionality will break! Also, it is a good idea to set database["noAutoQuery"] to true to avoid the initial query, which will fetch everything by default.