TACTIC Open Source
Get the value of a specific column by column name - Printable Version

+- TACTIC Open Source (http://forum.southpawtech.com)
+-- Forum: TACTIC Open Source (http://forum.southpawtech.com/forumdisplay.php?fid=3)
+--- Forum: TACTIC Discussion (http://forum.southpawtech.com/forumdisplay.php?fid=4)
+--- Thread: Get the value of a specific column by column name (/showthread.php?tid=234)



Get the value of a specific column by column name - Diego - 07-23-2021

I have a CustomLayoutWdg as cell in a row of a TableLayoutWdg
I want my widget to read/write the value of a sister cell and set the row as changed

From a bvr fired in my widget I get the parent row with:

Code:
var row = bvr.src_el.getParent(".spt_table_row");

And get the cells with:

Code:
var cells = row.getElements(".spt_cell_edit");


I can set the cell/row as changed with:

Code:
cell.addClass("spt_cell_changed");
row.addClass("spt_row_changed");
spt.table.set_changed_color(row, cell);


I can loop on every cell end get the value:

Code:
for (var i = 0; i < cells.length; i++) {
    console.log("TEST:", cells[i].getAttribute("spt_input_value"));
}



my problem is:
how can i get the value of a specific column?
Do I have to read the table header and get the column name index or is there e better, more readable solution?


RE: Get the value of a specific column by column name - remkonoteboom - 07-23-2021

There are a lot of methods in spt.table which can help you with these:

To get all the cell of a row:

Code:
let cell = spt.table.get_cell(element_name, row);


This function does exactly what you are describing above.  And then getting the value would be as you have:

Code:
let value spt.table.getAttribute("spt_input_value");


You can get a row by:

Code:
let row = spt.table.get_row(cell);


If you want all the cells for a given element:

Code:
let cells = spt.table.get_cells(element_name);


Hope that helps.


RE: Get the value of a specific column by column name - Diego - 07-23-2021

Thanks Remko, it helped a lot!

I ended up doing:
Code:
let my_value = bvr.src_el.value;
let row = spt.table.get_row_by_cell(bvr.src_el);
let sister_cell = spt.table.get_cell("colunm_name", row);
let sister_value = sister_cell.getAttribute("spt_input_value");

sister_cell.setAttribute("spt_input_value", sister_value + my_value);

sister_cell.addClass("spt_cell_changed");
row.addClass("spt_row_changed");
spt.table.set_changed_color(row, data_cell);

It is a simplification for the sake of readability, in reality the cell contains various fields, on change they are read, a json is build than it is merged with the one contained in the sister cell and overwritten.

I have one more question:

How do I "bind" a CustomLayoutElement to a column?

I mean if in the definition for a specific sType i have:

Code:
<element name="my_wdg_name">
    <display class="tactic.ui.table.CustomLayoutElementWdg">
      <view>my_wdg</view>
    </display>
</element>

I suppose I should put a "spt_input_value" and update it accordingly in my_wdg on_change behavior and then do the usual addClass("spt_cell_changed"), addClass("spt_row_changed") and pt.table.set_changed_color

but how do I tell the parent CustomLayoutWdg to save my my_wdg_name.spt_input_value to a specific column name when the row is saved?


RE: Get the value of a specific column by column name - remkonoteboom - 07-26-2021

I think I understand what you are trying to do.  You have a custom layout that contains UI elements that are in a table cell and you want to be able from that cell.

If that is indeed what you want to do, then all you need to do is set the spt_input_value attribute of the cell.  This is what saving changes in a table looks for.


Code:
var cell = el.getParent(".spt_edit_cell");
cell.setAttribute("spt_input_value", json_value);


and then do the spt_cell_changed, spt_row_changed that you are doing.

This might be useful to have as a singular function.

spt.table.set_cell_value() or something like that.