[Solved] Date format in JSON onRowClick event Table

Hi,

I have problem formating my date to pass it to a Popup params

Here is my code:

def runAction(self, event):
“”"
Fired when a row in the table is clicked.

Arguments:
	self: A reference to the component that is invoking this function.
	event: An object with the following attributes:
		row (int): The unique row index as it is represented in the source
		           data. Also known as the row ID.
		rowIndex (int): The row index as it is represented in the current
		                visible data.
		value (dict): The row's value as a JSON object.
"""
json = event.value
myDate = json["shift_date"]
system.perspective.togglePopup("tblEffTS","DruEfficaciteTypeStation", params = {'sDate':myDate})

The input data in the table is a string with a date format “yyyy-MM-dd” from SQL Query but is pushed as a string.
Somewhere this string is recognized as a date and is translated in “Fri Jun 10 2022 00:00:00 GMT-0400 (heure d’été de l’Est)” in json[“shift_date”]

I don’t know how to keep this string as a string in the process or to translate back the json value “Fri Jun 10 2022 00:00:00 GMT-0400 (heure d’été de l’Est)” to my original format “yyyy-MM-dd”.

Thanks for your help :slight_smile:

Hi Jonathan,

Have you tried the system.date.format system function? That should let you maintain your desired format through your script. Give that a try and let us know if it does what you need.

Hope this helps!

Hi jthorpe,

Thanks for your responce. I already try to use the function system.date.format on json[“shift_date”]. But the system don’t recognize the format as a date to transform into a string. There is already a prior transformation into json[“shift_date”] which is a string with the format “Fri Jun 10 2022 00:00:00 GMT-0400 (heure d’été de l’Est)”

But you gave me the idea to pre format the date in the table to force a format .

Here is my code:

def transform(self, value, quality, timestamp):
	output_json = [ ]
	style_red = {"color":"#ff0000"}
	style_green = {"color":"#00ff00"}
	for row in range(value.getRowCount()):
		row_object = {}
		row_value = {}
		row_style = {}
		for col in range(value.getColumnCount()):
			row_value[value.getColumnName(col)] = value.getValueAt(row,col)
			row_object['value'] = row_value
			if value.getColumnName(col) == 'pctEffAdjDrummond':
				if value.getValueAt(row,col) >= 1.02:
					row_style = style_green
				elif value.getValueAt(row,col) < 1.02:
					row_style = style_red
				row_object['style'] = row_style
			if value.getColumnName(col) == "shift_date":
				row_value['shift_date'] = system.date.format(value.getValueAt(row,col),"yyyy-MM-dd")
		output_json.append(row_object)
	return output_json

This have made the trick.

Thanks

Sorry, it’s look like I didn’t have the right format for the forum code quote.

Use > for quoting text written by someone else.
Use </> for code or put ``` on the line before the code and again on the line after. (That’s what the </> button does.)
Click the pencil icon to edit your previous post.

Thanks :slight_smile: I used:
[code] [/code]