• New Commercial Services Section

    We have now opened a commercial services section here on the forum. If you have a Fabrik project that you wish to have someone work on for you, post it under Help Wanted. If you are an application developer and wish to earn some money helping others, post your details under Fabrik Application Developers.

    Both of these are unmoderated. It will be up to both parties to work out the details and come to an agreement.

SOLVED List JS - get detail id

deant

Active Member
Hello,

Need little help how to grab detail id and other detail data using List JS plugin. I display my master-detail table each row separately. I was trying :

JavaScript:
var listdata = Fabrik.getBlock('list_32').options.data;
jQuery.each(rows, function(rowid, row) {...

console.log(rows) gets id from master table
row.master_table___element works fine
row.detail_65___element throwd an error.

What I missing here?
 
I tried several different ways and different approaches to get detail data but no luck. I was using JS, jQuery, userajax...

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

This look very promissing and easy to use but needs a row key witch I cant get by clicking button or chekbox. I can get master table ID, I can get master row, I can get joinedkey...but I cant grab detail___element_raw

Any suggestions?
 
I didn't try. But as far as I understand
console.log(ids); //outputs an array of the selected row ids,
so ids contains the selected rows' ids
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) ...
var myelement = listdata[0][2] .data.yourtable___yourelement;
So it's just one row data after the other:
First selected row: listdata[0][0] .data.yourtable___yourelement1;listdata[0][0] .data.yourtable___yourelement1_raw; listdata[0][0] .data.yourtable___yourelement2;...
so e.g. listdata[0][0] .data.yourtable___id_raw;

2nd selected row: listdata[0][1] .data.yourtable___yourelement1;listdata[0][1] .data.yourtable___yourelement2;...
etc
 
Last edited:
Ok, I tried and it's obvously not working in case of joined tables with "each row separately".
It's only showing the "main row" with the "last" selected child row.

I assume it's because with "each row separately" it's using the same HTML id for all rows.

It is working with "merge rows" showing multiple child rows JSON encoded.
 
I didn't try. But as far as I understand
console.log(ids); //outputs an array of the selected row ids,
so ids contains the selected rows' ids

Nope...ids return masters table ID:

id_master data1_raw data_2 repeat_id data_child1_raw data_child2 ids
1 15 abc 1 225 yxz 1
1 5 qwe 2 444 poi 1
2 11 mnb 1 111 asd 2
 
OK lets try differnet approch using php list plugin...I never used befor so need addvise if can be done what I like to do. The whole app is a bit compleks but here is a short scenario:

We have master-datail table (lets call it A) with button on the end. When user hit a button a new form (different table B) is open where we do some things with repeated data from table A. We prepopulete new form with some data from table A like (master: id, id_customer, id_location, id_user... and from repeat: id_item and two or three other data witch are only in detal table). When we save a new form we send bact to table A some params to know that we already do our things with repeat item. Table A is prefiltred so we do not display items which have been processed in a form.

The question is can I get master and repeat ID based on checkbox using php list plugin? I looked php list plugin'sp hp and js files but I did't saw some differens versus js list plugin.
 
I think I solved similar issue a while ago roughly with the following steps:

1) Added custom button to every row with calc element.
2) Set repeat table "id" element to "Show in list" and hide it with "display:none" in template's custom css file.
2) In list_xx.js I had click function of this button where I got the repeat id something like jQuery(this).parents('tr').find('.mytable_repeat___id').text().trim();
3) Sent the id to Fabrik's user_ajax.php and did the PHP-part there.
 
1) Added custom button to every row with calc element....

Great...this could works.

I didn't think of that possibility. I was just pushing the same thing aroun and around from different sides. Really stupid...

juuser thnak you very much :)
 
Last edited:
One other thought:
If your focus is on the repeat records and you are using "each record separately" it may be a way to create a list on the repeat table joining the main table (with repeat=no). You'll get the same joined records (you can order by main table id to have them "together") and php and js list plugin should do in this case.
 
@troester this is very good thought

I have completly done my code while ago and didnt see this "little mistake" - I allways grab last row data...so your solution requires less work for me...just few cliks and code tweaks and Im done ;)

Thanks :)

...both
 
I was playing around with jQurey for some time and found very simple solution:

Set table to "each record separately"

JavaScript:
// get list data by index - see console
var listdata = Fabrik.getBlock('list_123').options.data;
console.log(listdata);

// get checkboxes in table rows
var check = jQuery("input.fabrik_joinedkey:checkbox");

// get how many checkboxes are checked. If one chk box is checkeed lenght is 2
var checkbox_len = jQuery("input[type=checkbox]:checked").length;

//lets check if is realy one chkbox checked
if (checkbox_len === 2) {

    check.each(function(){

        if (this.checked){
      
            // get row index where is chkbox is checked
            var row_index = jQuery("input[type=checkbox]:checked").closest("tr").index();
            console.log(row_index);
      
            // substract 1 from jQuery row index to get listdata index
            var indx = row_index - 1;
            console.log(indx);
      
            // get data
            listdata[0][indx] .data.yourtable___your_element;
      
            // do someting with data
      
            //in code above I create a link to open new form and prepulate data
            window.open(url, "_self");  
        }
    });
}else{
    // need to explain?
        alert('Select one row.');
        window.location.reload(true);
}
 
Last edited:
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top