Table sorted by column only displayed correctly in Designer

I've got a table with no header sorted by a numeric column. When I see it in Designer, the table is correctly sorted. When I launch it on the browser, it resets the order. Any advice?

Show us how it's set up. There's not much we can do without any data.

Hello, I am having a similar issue. I worked through the manual as I understood the process to sort the columns, but they will not sort in the order I requested. The settings are all set the same in each column array. Hopefully I provided enough information that one of you can say what I am doing wrong. Thanks in advance.



image

First problem: field names have to match the names of the data columns.
In data.0 we can see column 'Age_of_WO'.
In colums.0.field we can see 'Age of WO' without the underscores.

They need to be exactly the same.

Ok, appreciate the feed back there. May I ask another question, a red box appears around the label if I leave out the underscores can this be fixed or manipulated somehow? I am unable to move on to edit the rest of the boxes. I had forgot about that issue when I posted originally.
image

It's warning you that you have spaces in JSON keys. I don't know the exact rules on this but it's not recommended although Ignition may let you away with it.

Use the underscore version in both locations.
Then define each column's title in,
columns.n.header.title (where n is the column number). You could write a script to do this for you by reading each data.0 field name, replacing the _ characters and writing to the header.title property. (You only need to do it once.)

2 Likes

You should make the columns settings match the data, not the other way around.
Also, I suggest you ALWAYS use underscore for your column names. You can always replace them with spaces via the header.title prop in the column's settings.

Actually, make your column names be valid jython identifiers. This will save you a lot of headache.

I have this in my lib, I use it to make sure everything matches that requirement when I have to use data that comes from somewhere I don't have control over:

import re

from unicodedata import normalize, combining

class MalformedKeyError(Exception):
	pass

def remove_accents(s):
	# NFKD: https://fr.wikipedia.org/wiki/Normalisation_Unicode#NFKD
	nfkd_form = normalize('NFKD', s)
	return "".join([c for c in nfkd_form if not combining(c)])

def make_key(s):
	"""
	Sanitize a string so it can be used as a key in an ignition object.
	
	If the first character is a digit, an underscore is added before it
	accents are removed
	leading and trailing whitespaces are removed
	other whitespaces are replaced with an underscore
	"""
	if isinstance(s, str):
		s = s.decode('utf-8')
	key = s.strip().lower()
	if not key:
		raise MalformedKeyError("Can't sanitize {!r} into a valid key".format(s)) 
	if key[0] in "0123456789":
		key = '_' + key
	return re.sub('\W+', '_', remove_accents(key))
1 Like

After correcting the labels to use all underscores and changing the column.header field to use spaces things look better. Still no cigar when it comes to the order.
image


image

Copy and paste the table component into a post here. See Wiki - how to post code on this forum.

If the table's data is coming from a binding then copy and paste the PROPS.data as well (because the binding won't work for us).

You will never see the Perspective JSON props display in the designer in any order but what Perspective wishes to show (because it uses java HashMap's, which do not order keys). The reason props.columns is a list is because lists are ordered, and providing props.columns in a specific order can drive the table's display in that order.

Perspective mapping objects in properties are ordered however the heck java wishes, for performance. You cannot change this.

Wait, are you expecting sortOrder to put your columns in a specific order ?
That's not what it's for. sortOrder specifies in which order columns are used to sort the data in the table.
Check the doc here, and particularly the given example:
Perspective - Table | Ignition User Manual

To have columns in a specific order... just put them in that order in the columns prop.

2 Likes

Oh sorry for the late reply, I ended up sorting it in the query itslef. If I encounter the same problem I'll check if it's already solved here and if not I'll post it here.

@pturmel Thank you for the help. This ended up being issue. I discovered it shortly after my last post and forgot to post an update.

@pascal.fragnoud Thanks for the help, I misunderstood that the first time through the manual. I just went back through and read it again after I had figured it out and it was clear.

Thanks everyone.