How to read the cell value from the table column, which has render type as view

Hi Team,
I have table of 3 columns with filled data, 4th column I added as pseudo column from named query(no data).
I this 4th column I want to add CheckBox/Toggle in each row. User can operates on each row and and the data will that CheckBox value on each row
Here some Screen Shots.



created Param for the template view
image


After saving in DB I am getting NULL value, since I am not able read Toggle value.

Please suggest

You don't need to embed a view for the toggle. Instead, set the boolean true or false condition in the column data, and then set the following (assuming it's column 3 we're working on):

columns.3.field : <set to name of boolean column>
columns.3.editable : true
columns.3.render : boolean
columns.3.boolean : toggle


Abnormal toggle

Don't change the label of a toggle switch with the true or false value. In the image above it reads "Abnormal is off" so it's not abnormal (which I presume is not what you mean)! Instead, just label the column as "Normal" and it will be obvious what it means.

1 Like

Hi,
I followed what you suggested,




Named query: SELECT *,'' AS Status,CAST(CURRENT_TIMESTAMP as DATETIME) AS Date_Time,'' AS UserName FROM statusTable.
Status column has no data. I need CheckBox in Status column, The user can select/deselect .If selected(true) I want to save it as Normal,If False Abnormal.
Here after I selecting first row checkBox , on selecting 2nd checkBox first checkBox is changing to False.

How I make changes to save the table data in DB on clicking on SAVE button.
output example required in Db:
image

Please guide.

Thank you.

You need to create an onActionPerformed event script to update the database. (Right-click on the button ...)

Tip: format your code using the </> button. See Wiki - how to post code on this forum. Then you'll get this and it will be obvious which are single and double quotes.

SELECT 
    *,
    '' AS Status,
    CAST(CURRENT_TIMESTAMP as DATETIME) AS Date_Time,
    '' AS UserName 
FROM statusTable
1 Like

sorry for the inconvenience.
here I need to read the value of STATUS column which may be checkBOX/Toggle to update in DB. I tried but it is saving null value in DB.

Please guide on this.

Show us your (formatted) code.

Hi,
Status column- need checkBOX/toggle- changed value to be saved in DB
Below is the code I am using to save all the rows at a time on clicking on SAVE button.

import system

    # Get the dataset from the Table component
    dataset = self.getSibling("Table").props.data

    # Convert the dataset to a PyDataSet for easy iteration
    pyDataset = system.dataset.toPyDataSet(dataset)

    # Define the SQL query for insertion into the target table
    query = """
    INSERT INTO [dbo].[ACTIVITYCHECLIST] (Asset_No, Activity, Maintaince_Name, Method, Time_In_Min, Special_Instruction, Frequency, Status, Date_Time, UserName)
    VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
    """

    # Loop through each row in the dataset
    for row in pyDataset:
        # Extract values from the dataset row based on your column names
        Asset_No = row["Asset_No"]
        Activity = row["Activity"]
        Maintaince_Name = row["Maintaince_Name"]
        Method = row["Method"]
        Time_In_Min = row["Time_In_Min"]
        Special_Instruction = row["Special_Instruction"]
        Frequency = row["Frequency"]
        Status = row["Status"]  # Extract Status from the dataset directly
        Date_Time = row["Date_Time"]  # Ensure this is in the proper datetime format
        UserName = row["UserName"]  # Extract UserName from the dataset directly

        # Print Status and UserName for debugging purposes
        print("Status:", Status)
        print("UserName:", UserName)

        # Execute the query with the extracted values
        system.db.runPrepUpdate(query, [Asset_No, Activity, Maintaince_Name, Method, Time_In_Min, Special_Instruction, Frequency, Status, Date_Time, UserName])

On my Designer , below is the table:

image
I am getting null value in DB.

Db structure:

The table status column is returning a boolean. Your table status column is a string so I'm not sure what would happen there.

It looks like you're using MS SQL and so you should try
[Status] BIT
in the table definition instead.

You could also simplify your code:

    query = """
    INSERT INTO [dbo].[ACTIVITYCHECLIST] 
        (Asset_No, Activity, Maintaince_Name, Method, Time_In_Min, 
        Special_Instruction, Frequency, Status, Date_Time, 
        UserName)
    VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
    """

    for row in pyDataset:
        system.db.runPrepUpdate(query, [
            row["Asset_No"],
            row["Activity"],
            row["Maintaince_Name"],
            row["Method"],
            row["Time_In_Min"],
            row["Special_Instruction"],
            row["Frequency"],
            row["Status"], 
            row["Date_Time"] ,
            row["UserName"]
        )

Hi,
I changed the the data type of Status column into BIT. below is my SQL table.
image
I called this table using named query. This is the Operator entry table.


for status column need to use check box/toggle. After changing the value in status column, I need to save the updated data into another table. I am able to save the table by using above script, but status column value is not saving. since T/F value is not sitting in the cell. same for DateTime column need to put Datepicker operator has to choose the date and update.

Thank you


Figure 1. Setup for subview params.
For more on this see the bottom of Table Column Configurations | Ignition User Manual.


Figure 2. On the toggle switch add a script to send a message to a message handler on the table.

Code:

def runAction(self, event):
	# Pass the change back to the calling table.
	payload = {
		"row" : self.view.params.row,
		"value" : self.props.selected
	}
	system.perspective.sendMessage("statusUpdate", payload)


Figure 3. Configure a script on the table as shown.

Code:

def onMessageReceived(self, payload):
	self.props.data[payload['row']].status = payload['value']

You'll need to do a similar job for the datepicker column.

Notes:
You need to set your Date_Time column field name and set the column's render : date.
I see you have the word "Normal" in the Status column. I hope it doesn't change to "Abnormal" when the toggle is off. See post #2.