Automatically Change Row or Column Labels
(Redirected from Change row or column labels by name)
Jump to navigation
Jump to search
These functions, which can be included in your own table JavaScript, are used to change the label of a row or column by specifying the existing label and the label that you want to change it to.
// Change the label of a given column
function changeColumnLabel(current_label,new_label) {
if(table.columnIndex(current_label) != -1) { // If there is a column with the specified label
var col_labs = table.columnLabels; // Get the column labels
col_labs[table.columnIndex(current_label)] = new_label; // Change the one of interest
table.columnLabels = col_labs; // Set the column labels
}
else alert("There is no column called \"" + current_label + "\""); // Otherwise, present a warning message
}
// Change the label of a given row
function changeRowLabel(current_label,new_label) {
if(table.rowIndex(current_label) != -1) { // If there is a row with the specified label
var row_labs = table.rowLabels; // Get the row labels
row_labs[table.rowIndex(current_label)] = new_label; // Change the one of interest
table.rowLabels = row_labs; // Set the row labels
}
else alert("There is no row called \"" + current_label + "\""); // Otherwise, present a warning message
}
Once these functions have been included in your table JavaScript, you can call them whenever you need to change a label. For example, if your table includes a row called "Coke", and you wish to change the label to "Coca Cola", then you could use the following.
changeRowLabel("Coke", "Coca Cola")
See also
- Table JavaScript and Plot JavaScript for an explanation of how to run this code.
- Table JavaScript and Plot JavaScript Reference for technical information.
- Table JavaScript and Plot JavaScript Examples Library for other examples.
- JavaScript for information about the JavaScript programming language.
- QScript for tools for automating projects using JavaScript.
- JavaScript Variables for detail on how to create new variables in the Variables and Questions tab using JavaScript.