Hide id column from 'Table' component

Hi,

Why can't I hide the 'id' column in a table component i perspective?
I managed to hide other columns, but if I try to hide 'id' it will be shown as the last column.
I have this code;

hiding the column named 'copoPLC' works fine but not the 'id' one.
Any idea what goes wrong here?
The 'id' column is the primary key for the table but that shouldn't affect anything since I retrieve the SQL table as a dataset.

Many of the column options only work when the columns.x.field property matches the name of a column in props.data. If you haven't done that then I wouldn't expect the table component to know which column to hide.

1 Like

The dataset column name is the same as props.column[number].field

OK. How about the line,
if rows[1] == u'id' or rows[1] == u'copoPLC':

Is id really column 1?

'id' is the first column in the dataset.

OK. I'm expecting that to return an integer but you seem to be checking for two string values in column 1, 'id' or 'copoPLC', and if either are found in column 1 of any row in the dataset you are going to hide the whole column. Why would the id column contain the value 'id'?

That script is terribly inefficient, repeating the same logic for every row in the dataset when every row is guaranteed to have the same structure; assuming a dataset of, say, 100 rows, you'd looking at executing all of this logic 100 times while your dataset likely only has N number of columns. Even of those N columns, you only ever actually configure Table columns for rows[0] and rows[1].

On top of that, self.parent.parent.getChild("Table").getChild("Table") should fail to identify a component as Tables are not containers and therefore should (almost) never have children.

This (pseudo) code should configure your columns as needed:

# your code here, up until just after you've acquired your dataset
headers = system.dataset.getColumnHeaders(dataset)
columns = []
ignored_columns = ["id", "copoPLC"]
for i, header in enumerate(headers):
    if header not in ignored_headers:
        should_be_visible = i < 22  # based on your provided max column count
        columns.append({"field": header, "editable": True, "dateFormat": "MM/DD/YYYY HH:mm:ss", "visible": should_be_visible})
self.parent.parent.getChild("Table").props.columns = columns
1 Like