You may want to show special information for products you have, which aren't available in the default selection of columns in our Calculation View.
This article will guide you through how to create a basic custom column.
Creating the Class
To create your own calculation column, we recommend extending from BasicPartColumn
.
Here is a very basic implementation example:
/** * Column Singleton. */ public const ExamplePartColumn exPartColumn(); /** * Example Column. */ public class ExamplePartColumn extends BasicPartColumn { /** * Create a new column with unique key. */ public constructor() { super("exampleCol", pkg=#:package); splitOn = true; } /** * The value shown in the cell of this column. */ public Object value(Part part, Space space) { return "custom value"; } }
The constructor()
passes on the unique key of this column along with the package used to identify the rs file used for this column.
splitOn
is turned on to indicate the ability to split into rows for each column value. It's a necessity for the core code to register this column as visible.
The value()
method basically returns the value shown in the cell.
In this example, custom value is shown in the Calculation cell.
Lastly, a singleton of the class is initiated above for column registration and voting.
rs File
Since the code managing the columns are located in the core base, it makes sense for it to require the package data to fetch the rs connected to the class.
- The first method is to tie the package in the constructor of the custom column, this makes every rs fetch request to look into this package:
/** * Create a new column with unique key. */ public constructor() { super("exampleCol", pkg=#:package); splitOn = true; }
-
The second method is to specifically fetch a rs from a given package for each returning method:
/** * Column label (rs). */ public str label() { return getRs(_key # "PartColumnLabel", this.pkg); }
Column Registration and Voting
Now to connect the custom column with the processes responsible in handling columns, we have to use only one function, called within the initiation/start phase of your Extension.
/** * Example Extension. */ private class ExampleExtension extends UltraLazyExtension { /** * Start. Place Init code here. */ public void start(ExtensionEnv env) { registerPartColumn(exPartColumn, upvote=true); super(env); }
...
}
To register, pass the column singleton to registerPartColumn()
.
Optionally, you can set the upvote
argument to true.
CET is open for multiple Extensions to be installed, but if every Extension wants their columns to be shown, it will get messy really fast.
The upvote system is created to manage that.
Here is a separate article explaining the voting system
Comments
0 comments
Please sign in to leave a comment.