I am wondering if someone could help me with my issue regarding dynamic tables. In my dynamic table, and before that in transactional data I have some field that are strings and some that are floats. I had to check treat empty as 0 for float values, otherwise it would report a mistake, or everything would turn gray.
So then in float fields instead of having empty field I have 0. That part makes me problems with dynamic tables - although all other fields are empty, those are filled with 0 and table does not hide.
I have tried making conditional to hide the table if those two values are equal 0, but it doesnt work if there are more details than 1.
for example
if (record.tables.kredit[“Iznos u docnji”] == 0 && record.tables.kredit[“A_Max Iznos u docnji”] == 0 ) {
results.attr(“data-conditional”, “”);
results.hide();
} else {
results.show();
}
The problem here is that even when all of the field values are empty, the detail table itself still seems to have a bunch of empty records. This means our built-in “hide when empty” feature for dynamic tables won’t work.
This is an unusual way to structure the input data and should ideally be solved on the data mapper side. If a record is empty you should not add it to the detail table.
If that is not an option you could consider adding a script that targets the table element and checks if all records in the detail table are empty:
const isRecordEmpty = rec => !rec["Iznos u docnji"] && !rec["A_Max Iznos u docnji"];
if (record.kredit.every(isRecordEmpty)) {
results.hide();
}
Note: I tried to generalize this script using Object.values(rec.fields) but there seems to be a bug somewhere that prevents that from working.
Thank you all on your help! I have found the way.
I had to make a text script for each field of interest, make script like this:
results.each(function(index) {
var field, result = “”;
field = record.tables["kredit"][index].fields["Iznos rate"];
if (field !== 0) result += formatter.currencyNoSymbol(field);
else result = "";
this.html(result);
});
and I had to delete data-field=“Iznos rate” in the source from the table element.
I posted this in case someone else needed it.
Thank you once more!