Hi!
I would like to add a column with checkboxes on a table in perspective.
Later on I will use this checkboxes to filter another column.
Hi!
I would like to add a column with checkboxes on a table in perspective.
Later on I will use this checkboxes to filter another column.
props.data
.column.n.render : boolean
column.n.boolean : checkbox
Tip: don't delete and repost. Use the edit button on your first post.
I just added a column boolean checkbox but is not showing the checkboxes
props.data
. You could generate this in your SQL:SELECT
column0,
column1,
column2,
column3,
FALSE AS check
FROM ...
field
property.Now just appear a 0
OK, it looks like SQL is converting TRUE and FALSE to 1 and 0.
Try this:
SELECT
column0,
column1,
column2,
column3,
'false' AS 'select'
FROM ...
SELECT A.ASSET "text",
0 "select",
TO_NUMBER(APA.PARENTASSET) "Zone",
TS.ID_SEDE AS "id"
Shouldn't that be,
SELECT A.ASSET AS 'text',
0 AS 'select',
Also, see Wiki - how to post code on this forum.
The query is ok, I just checking why checkboxes doesn´t appear...
The field
property "check" does not match the column name "select".
("select" isn't a very good column name in SQL!)
yes, still don´t get why check column is not showing and why select column does
Because you don't have a 'check' column in your SQL. Look at props.data
and I expect you will see a 'select' column and no 'check' column.
You need columns.4.field : select
.
Is working, but now can´t check the checkboxes as they all have value "0" I guess I will need to add some script
Cheers
column.4.editable : true
Yes, you will need to write code.
Ok, I will add based on previous code something like:
# Assuming this script is triggered by an onClick event from a table component
# `event` is the object that contains details about the event that was triggered
if event.button == 1: # Check if the left mouse button was clicked
# Get the selected row index
selectedRow = self.props.selection.selectedRow
if selectedRow is not None: # Ensure there is a selected row
# Accessing the table's data
data = self.props.data
# Check if the selected zone is within the user's allowed zones
if data[selectedRow]['Zone'] in system.util.getGlobals().get('userZones', []):
# Get current state of the 'select' checkbox
currentSelectValue = data[selectedRow]['select']
# Toggle the value
newValue = 0 if currentSelectValue == 1 else 1
# Update the 'select' column in the data
# Make a deep copy of the data to modify it
import copy
newData = copy.deepcopy(data)
newData[selectedRow]['select'] = newValue
# Set the modified data back to the table
self.props.data = newData
But don´t know where to add it, on the column itself?
No, to change the checkbox in run mode you have to edit the cell. The default is,
cells.allowEditOn : double-click
.
You might prefer,
cells.allowEditOn : single-click
.
Then click the checkbox.
You only need code to update your database or whatever you want to do.
See also:
Ok thanks, and now where should add my on click script?
It depends what you want to do.
I would like to filter another table (table-1) with same 1st table depending on wich checkbox from (table-2) I click