[SOLVED] List Javascript-Plugin and accessing list data!

mudshark79

Member
First: happy new Year! Overall thanks to the team, I really enjoy rewamping some web apps I already once did with version 2.x. I think Version 3.x is a great move forward in ease of use for the "developer" or educated-user like me. Didn't encounter any major bugs yet and really love working with it :)!

Some question remains, just for my understanding:

The Wiki Entry for the Javascript-Plugin is silent on how to access other data than solely ids and rows of the marked entries:
http://fabrikar.com/forums/index.php?wiki/javascript-list-plugin/

In order to open a form with the help of the javascript-plugin and in order to prefill certain dropdowns in the form, the id of the row was not enough. As an absolute quite a noob in javascript things i didn't find a solution for accessing the other data of list, but did find a workaround by "simply" fetching the missing data via an User-Ajax call directly out of the db. This thread helped quite a bit:
http://fabrikar.com/forums/index.ph...abase-using-javascript-php.39351/#post-198637

The question remains: is there another possibility to access the lists data via javascript?

I will try to post my workaround tomorrow if it turns out to be the only possible way, i can imagine that someone else may also could be curious sooner or later ....

Regards,

Matthias
 
Sorry about the late reply, I've had this one open in my browser for ages ...

Yes, you can get at the list's data through the list objects 'data' option ...

Code:
var listdata = Fabrik.getBlock('list_123').options.data

... would get you the main data object. That is then grouped, according to your list's current display, using sequentially numbered indexes starting at 0. If your display is not grouped, it'll all be in listdata[0]. Which is then indexed by row number (not PK value, just the sequential display count, starting at 0). And that then contains another 'data' object, which has all the element values in it. So if you wanted to get the value of 'yourtable___yourelement' in the third row of the first (or only group) ...

Code:
var myelement = listdata[0][2] .data.yourtable___yourelement;

Note that this will give you the "formatted" value, so (for example) if you use an element as a detail view link, that'll give you the data with all A tag round it. If you just want the raw, unformtted data, just append _raw to the element name (yourtable___yourelement_raw).

And of course you can iterate through the data object, or otherwise do with it what you need to, using standard JS.

I've added this to the Wiki page you referenced, although there's probably a better, more generic place to document it, I wanted to get this into in to the wiki.

-- hugh
 
OK, got it sorted out. I must confess that the given explanations in the Wiki already fulfilled my needs because the
Code:
console.log(rows);
already contains the data of the row which is quite obvious if one really does what is written there. I did beginners-mistakenly try to shed a ligth into the data structure of the given objects with "alert(stgh)", which didn't get me anywhere.

Your additional info just provides a way on how to retrieve the whole list-data-structure not depending on the chosen row, rigth? :)

But then again I experienced different problems. As my "list__elemnentname" all begin with a number,I simply couldn't use the method like described by you because the console gave me "some error ILLEGAL" and I had to try something like this, to finally really get the value out of the object:
Code:
var elementname = "04_abrechnungen___faktor_teilabrechnung";
var myelement = listdata[0][0].data;
var myelement = myelement[elementname];
console.log(myelement);

Finally I suppose there is a typo in
Code:
var myelement = listdata[0][2] .data.yourtable___yourelement;
but because of my general struggle described above I'm not sure about it, but isn't it:
Code:
var myelement = listdata[0][2].data.yourtable___yourelement;
more likely? Please correct me if wrong, I suppose this javascript and its objects do have several surprises for me noob up the sleeve.

Anyway thanks again and happy to learn (even though the hard lesson again :cool:).



Regards,Matthias
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top