Last active
September 23, 2021 19:57
-
-
Save cgillis-aras/67e8ab83b07f16729e8e730ebb686866 to your computer and use it in GitHub Desktop.
Sample code to update the value of a property's cell in a relationship grid.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var set_property = setRelatedItemProperty(relationshipID, "owned_by_id", "DBA5D86402BF43D5976854B8B48FCDD1"); | |
// At this point the value is set on the item in the dom, but it does not seem to appear in the grid | |
// By debugging into this function, the item also does not seem to be added to the grid at this point, so we'll need to handle this logic in a timeout | |
setTimeout(function(relID) { | |
var gridApp = this.gridApplet; | |
var columnName = gridApp.GetPropertyColumnName("owned_by_id"); | |
gridApp.SetCellValue(relID, gridApp.GetTrueColumnIndex(columnName), "Innovator Admin"); // <-- This should be the keyed_name of the item | |
}, 50, relationshipID); | |
/* | |
* The column names in the grid are based on the property names, but don't match exactly. This function will figure | |
* out the column name from the property name. | |
*/ | |
gridApplet.GetPropertyColumnName = function(propName) { | |
// All columns follow the format of "property_name" + "_Identifier". For example, the name of the quantity column is "quantity_D" with D | |
// being an identifier for a digit. We want to strip out the "_Identifier" so we can compare directly with the property name | |
var columnName = this.grid_Experimental.nameColumns.filter(function(colName) { | |
var columnPropertyName = colName.substr(0, (colName.length - 2)); | |
return (columnPropertyName === propName); | |
}); | |
return columnName[0] || ""; | |
} | |
/* | |
* We want to use gridApp.SetCellValue(rowId, colIndex); in order to set the value of the column in the grid. | |
* | |
* Ideally, we could use gridApp.GetColumnIndex(columnName); to get the index of the column, but this actually returns an | |
* incorrect value in mixed-property grids like Part BOM. So we have to use a slightly-more involved method of getting the correct | |
* column index. | |
*/ | |
gridApplet.GetTrueColumnIndex = function(colName) | |
{ | |
var wrongColumnIndex = this.GetColumnIndex(colName); | |
var trueColumnOrder = this.grid_Experimental.order; | |
// grid_Experimental.order contains a mapping between the wrong column indecies and the correct ones | |
return trueColumnOrder.indexOf(wrongColumnIndex); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment