How do I hide table columns?

@jwal485 Below is some button click code that will give you an idea of how to proceed. Substitute your actual field names obviously. There are other ways of getting the totals for columns, but I’m assuming that you are using a dataset to populate the table. The syntax with braces, brackets, and commas in the column assignment code needs to be adhered to. The key to remember is that the comma serves as the separator from one column to the next. The editor will draw your attention to any errors. The field key is what goes in the dataPath property, and the id property just needs a unique value.

export function button1_click(event) {
 // you would run this after the table data is refreshed with a new filter
 // this will give you an array of the table data
 let rows = $w("#table1").rows;
 console.log("ROWS: ",rows);
 // initiate variables to sum the amounts in the fields that potentially may have no values
 let total2 = 0, total3 = 0;
 // loop through the array and total the values in the columns you want to check.
  rows.forEach((row) => {
      if (row.test2){
          // requires number function because numbers are strings in table array
          total2 = total2 + Number(row.test2)
      }
      if (row.test3){
          total3 = total3 + Number(row.test3)
      }
  })
  console.log(total2);
  console.log(total3);
 // derive a boolean value to apply to the columns visible property below 
 let visible2 = (total2 > 0) ? true:false;
 let visible3 = (total3 > 0) ? true:false;

$w("#table1").columns = [
  {
 "id": "col1",
 "dataPath": "firstName",
 "label": "First Name",
 "width": 125,
 "visible": true,
 "type": "string",
 "linkPath": "link-field-or-property"
  },
  {
 "id": "col2",
 "dataPath": "lastName",
 "label": "Last Name",
 "width": 150,
 "visible": true,
 "type": "string",
 "linkPath": "link-field-or-property"
  },
  {
 "id": "col3",
 "dataPath": "test2",
 "label": "Test 2",
 "width": 100,
 "visible": visible2,
 "type": "number",
 "linkPath": "link-field-or-property"
    },
  {
 "id": "col4",
 "dataPath": "test3",
 "label": "Test 3",
 "width": 100,
 "visible": visible3,
 "type": "number",
 "linkPath": "link-field-or-property"
  }
];
}