Table: type of value when editing a cell

Hi guys,
I’m on Ignition 8.1.15

I noticed that, except for booleans, a cell edit always returns a string value, ie. event.value in onEditCellCommitis always a string. Is that expected? Do you guys use views to return typed values, or you cast them using for example, float(event.value), in the event?

It might help if you can explain exactly what you are trying to do? Context is key.

I thought I could set a type in a column in a Perspective Table, ie. this column contains numbers. However when I edit a value in the column, it gives me a string instead of a number, which I thought was odd.

Like @andrews says, context. Show us what you are trying to do. This, for example is a table with a dataset binding pulling power meter data. You can see that the type is an Integer. Event.Value will be an integer for this field.
image

Oh… using a Dataset. Interesting.
I’m using table.data as an array of objects instead.

Here, I entered 1 in the population property using the Perspective Property Editor. By its orange color, we can see that it is typed as a number.
image

Then in preview mode, I edited the column and set 2. It’s now colored as a string, green.
image

I assumed that setting the render prop in table.columns to number would change the cell editor to a numeric entry field, but I guess not :confused:

I’ll try using a DataSet.

table.columns

[
  {
    "field": "enabled",
    "visible": true,
    "editable": true,
    "render": "auto",
    "justify": "auto",
    "align": "center",
    "resizable": true,
    "sortable": true,
    "sort": "none",
    "viewPath": "",
    "viewParams": {},
    "boolean": "checkbox",
    "number": "value",
    "progressBar": {
      "max": 100,
      "min": 0,
      "bar": {
        "color": "",
        "style": {
          "classes": ""
        }
      },
      "track": {
        "color": "",
        "style": {
          "classes": ""
        }
      },
      "value": {
        "enabled": true,
        "format": "0,0.##",
        "justify": "center",
        "style": {
          "classes": ""
        }
      }
    },
    "toggleSwitch": {
      "color": {
        "selected": "",
        "unselected": ""
      }
    },
    "numberFormat": "0,0.##",
    "dateFormat": "MM/DD/YYYY",
    "width": "",
    "strictWidth": false,
    "header": {
      "title": "",
      "justify": "left",
      "align": "center",
      "style": {
        "classes": ""
      }
    },
    "footer": {
      "title": "",
      "justify": "left",
      "align": "center",
      "style": {
        "classes": ""
      }
    },
    "style": {
      "classes": ""
    }
  },
  {
    "field": "date",
    "visible": true,
    "editable": true,
    "render": "date",
    "justify": "auto",
    "align": "center",
    "resizable": true,
    "sortable": true,
    "sort": "none",
    "viewPath": "",
    "viewParams": {},
    "boolean": "checkbox",
    "number": "value",
    "progressBar": {
      "max": 100,
      "min": 0,
      "bar": {
        "color": "",
        "style": {
          "classes": ""
        }
      },
      "track": {
        "color": "",
        "style": {
          "classes": ""
        }
      },
      "value": {
        "enabled": true,
        "format": "0,0.##",
        "justify": "center",
        "style": {
          "classes": ""
        }
      }
    },
    "toggleSwitch": {
      "color": {
        "selected": "",
        "unselected": ""
      }
    },
    "numberFormat": "0,0.##",
    "dateFormat": "MM/DD/YYYY",
    "width": "",
    "strictWidth": false,
    "header": {
      "title": "",
      "justify": "left",
      "align": "center",
      "style": {
        "classes": ""
      }
    },
    "footer": {
      "title": "",
      "justify": "left",
      "align": "center",
      "style": {
        "classes": ""
      }
    },
    "style": {
      "classes": ""
    }
  },
  {
    "field": "population",
    "visible": true,
    "editable": true,
    "render": "number",
    "justify": "auto",
    "align": "center",
    "resizable": true,
    "sortable": true,
    "sort": "none",
    "viewPath": "",
    "viewParams": {},
    "boolean": "checkbox",
    "number": "value",
    "progressBar": {
      "max": 100,
      "min": 0,
      "bar": {
        "color": "",
        "style": {
          "classes": ""
        }
      },
      "track": {
        "color": "",
        "style": {
          "classes": ""
        }
      },
      "value": {
        "enabled": true,
        "format": "0,0.##",
        "justify": "center",
        "style": {
          "classes": ""
        }
      }
    },
    "toggleSwitch": {
      "color": {
        "selected": "",
        "unselected": ""
      }
    },
    "numberFormat": "0,0.##",
    "dateFormat": "MM/DD/YYYY",
    "width": "",
    "strictWidth": false,
    "header": {
      "title": "",
      "justify": "left",
      "align": "center",
      "style": {
        "classes": ""
      }
    },
    "footer": {
      "title": "",
      "justify": "left",
      "align": "center",
      "style": {
        "classes": ""
      }
    },
    "style": {
      "classes": ""
    }
  }
]

Thank you, that was helpful. You are correct, its treating it as a string which seems odd. Fortunately you can work around this by casting to an int. Hopefully that is of some help.

This was what i did with my very simplistic test, but you could check the edit is for the appropriate column before doing a cast operation:
self.props.data[event['row']][event['column']] = int(event['value'])

2 Likes