Add conditions on dynamic table rows and headers

PlanetPress Connect 2021.1

Standard detail table with 5 field in each row

  • Record.detail
    • Field1
    • Field2
    • Field3
    • Field4
    • Field5

If I select make condition on a cell, I can’t see the detail table in the GUI interface.

image

I want to remove the entire row if a string is contained in a specific field, such a if Field4 contains “internal”

Also when all of the rows are removed then also remove the headers. For example the detail table has 3 detail records where Field4 all contain the string “internal” and are removed. We don’t want the header to be displayed either.

Removing a row based on a value is not possible via the condition wizard today but it is possible using a script.

Create a script that selects the rows in the tbody of your table:
Selector. #table tbody tr

Open the Options section at the bottom of the Edit Script dialog and change the scope to Each matched element. This exposes the “this” object for your script which provides access to the record used to generate this dynamic row.

The following script places the value of a field from the respective record in a variable and a basic if statement is used to check the value. When the result is true it will remove the row from the table.

let prodNo = this.record.fields.Number;

if( 'p78151922' == prodNo ) {
	this.remove();
}

Hope this helps for part one.

On part two, I guess you want to delete the entire table, is that correct?

Erik

each-matched-element-in-dynamic-table

Delete the table when it is empty could be achieved using script that selects the table and subsequently checks the number of rows in the tbody.

let rows = query('tbody tr', results ).length;

if ( 0 == rows ) {
	results.remove();
}

Erik

PS. This uses the standard Results set scope.

The first script seems to work to remove the row if the cell (modified to includes rather than equal) a string.

let cellcheck = this.record.fields.name;

if(cellcheck.includes('ACH')){
this.remove();
}

image

The second script appears to delete the table regardless.

let rows = query('tbody tr', this ).length;

if ( 0 == rows ) {
	results.remove();
}

image

Debug always shows zero rows even when there should be several remaining.

Hi @UomoDelGhiaccio,

Please use the following line of code instead:

let rows = query("tbody tr", results).length;

Because the following lines of code:

let rows1 = query("tbody tr").length;
let rows2 = query("tbody tr", this).length;
let rows3 = query("tbody tr", results).length;

logger.info("rows1: " + rows1);
logger.info("rows2: " + rows2);
logger.info("rows3: " + rows3);

will result in the following logging:

rows1: 6
rows2: 0
rows3: 3

When I have a Print Context Section to which I’ve added two table elements with a different ID and three rows each.

Works much better.

let rows = query("tbody tr", results).length;

if ( 0 == rows ) {
	results.remove();
}

image

Thanks

My bad, this should indeed be results. I’ll update my earlier reply for future reference.

1 Like