Forum OpenACS Development: Re: SharePoint: AJAX Tables for List Builder?

Collapse
Posted by Taras Mitran on
I did not use list builder. The examples from Sencha are basically where I started. You will notice that JSON is used for the data for the table, the list of columns for the table, and table definition itself - so its easy to programatically insert something dynamic instead of writing that manually. For example, instead of columns 'a', 'b' you could have a multirow that returns the columns thats specific to a group or user.

This is a really really basic example I wrote for someone a year ago of how to get data from a db_multirow into a grid:

Sencha Thread

There are of course better ways to do what I was doing, but the idea is to start with the Sencha grid then get dynamic data into it as a starting point. We've since written a db_multirow2json function, plus postgresql 9.0 will have an extension that converts the query directly to json (that my company is actually the sponsor for).

Here is a simple multirow2json proc written by one of our guys:

namespace eval prototype {}

ad_proc -public prototype::mr2json {
{-key_column "id"}
datasourcename
} {
Converts a template::multirow to a JSON string. The current design creates an
object where each value is a record and the key is the value that could be used
to update or retrieve the original record.

Future designs could include the option to return an array of objects.

@author Justis Peters justis AT ivc.com

} {
set cols [template::multirow columns $datasourcename]
append ret "{\n"
template::multirow foreach $datasourcename {
append ret "'[set $key_column]':"
append ret "{"
foreach c $cols {
set currval [regsub -all {'} [set $c] {\'}]
append ret "'$c': '$currval',"
}
append ret "},\n"
}
append ret "}"
return $ret
}

Collapse
Posted by Brian Fenton on
Taras,

thanks a lot for the info - that looks really good. I'll take a deeper look when I get a chance.

cheers!
Brian

Collapse
Posted by Taras Mitran on
BTW, the perl module for postgres is about done:

andrew=# select query_to_json('select usename, usecreatedb, valuntil,usesysid from pg_user limit 2');
query_to_json
---------------------------------------------------------------------------------------------------------------------------------------------------
[{"usesysid":10,"usecreatedb":true,"valuntil":null,"usename":"andrew"},{"usesysid":16392,"usecreatedb":false,"valuntil":null,"usename":"blurfl"}]

Its very nice for doing ajax calls with - including tables.