Hi,
I am new in PlanetPress, and use it for creating invoices with printer spool data.
Therefore, i have created a table, which shows all wanted data and subtotals.
Now I want to hide a column only if the all rows of this column are empty.
What would be the best way to do this?
I have tried a conditional script for the header column, but it does not work. What can I do, to get the correct result?
var i=0, isEmtpy=1;
for(i=0; i<record.tables["Article"].length; i++ ) { if (record.tables["Article"][i].fields["Articlenumber extern"].trim() != "")
{
isEmpty = 0;
}
}
if (isEmpty == 1) {
results.attr("data-conditional", "");
results.hide();
} else {
results.show();
}
Hi,
I should have managed to loop through the table and check if there is any entry in the column.
var i=0; isEmpty=1;
for(var tableRow in record.tables.Artikel)
{
if (!record.tables.Artikel[tableRow].fields["Artikelnummer extern"].trim().equals(""))
{
isEmtpy=0;
break;
}
}
if (isEmpty == 1)
{
record.tables.Artikel[tableRow].fields["Artikelbez extern"].
}
My actual problem is how to hide the column if “Artikelnummer extern” is empty.
Thank you for your answers.
I am very new with PlanetPress Connect and JavaScript.
Nbecker
Note, my inspiration for this came from here: asp.net - How to hide columns in HTML table? - Stack Overflow
HTML, javascript, and CSS being somewhat of a widespread standard, we can thankfully find many resources online for this sort of thing.
So let’s take apart my script below, bit by bit and try to understand what it’s doing.
- The selector #invoice-data is simply getting us into the table that we care about.
- My IF statement is just a stand-in here. Normally this condition is going to be based off of your data, so above this you might have a small loop looking at your table. If every record is empty, you set the variable allRecordsEmpty to true.
- The query method is special to Connect. It allows us to inject secondary selectors into our script. Note that there are two parts. First, the selector ‘tr td:nth-child(1)’ and next the context of results. What we’re saying here is get everything that matches our selector inside our limited context. In this case results is a callback to our original selector of #invoice-data. Put simply, we’re only selecting those objects that match our second selector AND are included in our first selector. This way we’re not accidentally hitting every TR on the page…
You can get more info on nth-child here. but we’re essentially telling it to get every 1st td in every tr in our table. In other words, the first column of our table. Change the (1) to be whatever column you’re looking to hide.
- Lastly, we’re using the CSS method, again this is special to Connect, to actually apply the CSS we want to these objects. Display None will effectively hide them.
Thank you very much.
That works exactly as I wanted.
And with a little extension, I can remove complete lines from a table.
One final question: Is there an easy way to detect if all rows of a specific column are empty?
Nbecker
The only good way I know is to loop through each record and check, much like you`re doing above.