grids Methods
Item Index
Methods
addButton
(
-
[options]
)
Object
-
[options]
Adds a button to the column on the right-hand side of a grid.
Parameters:
-
[options]
Object optionalSpecifies an object representing the button ID and icon.
-
id
StringSpecifies the button ID.
-
image
StringSpecifies the icon to show on the button.
If this parameter is omitted, the accept.png icon is used by default.
You can choose one of the following icons:accept.png lock-14.png email.png error.png exclamation.png help.png information.png lightbulb.png -
click
FunctionSpecifies the function to execute when a user clicks the button.
Add two parameters to the function to make the current row data and the current row index available to the function.
-
Returns:
Examples:
// Adds a button with the default icon to the grid.
// The button ID is myButton followed by the index of the row where the button is located.
// For example, if the button is on row 0, the button ID is myButton0.
// If you have applied a filter to the grid, the button ID will be equl.
crm.grids("CaseList").rows().addButton({
"id": "myButton",
click: function (row, index) {
$.each(row, function (key, val) {
if (row[key].hasOwnProperty("value")) {
crm.log(row[key]["value"])
}
})
}
});
// Adds a button to the grid on rows that have a case_stage value equal to Confirmed.
crm.grids("CaseList").filterWhere("Case_Stage", "eq", "Confirmed").addButton({
"id": "myButton",
"image": "exclamation.png",
click: function (row, index) {
$.each(row, function (key, val) {
if (row[key].hasOwnProperty("value")) {
crm.log(row[key]["value"])
}
})
}
})
addCell
(
-
row
-
column
-
obj
)
-
row
-
column
-
obj
Adds a cell to a grid.
Parameters:
-
row
NumberSpecifies the row to which to add the cell.
-
column
NumberSpecifies the column to which to add the cell.
-
obj
ObjectSpecifies an object representing the cell.
-
type
StringSpecifies the cell type.
You can specify one of the following types:- checkbox - link - text - image
-
[id]
String | Function optionalSpecifies the ID to assign to the cell.
-
[value]
String | Function optionalSpecifies the value to assign to the cell.
-
[text]
String | Function optionalSpecifies the text to include in the cell.
You can only use this option if the cell type is link or text. -
[href]
String | Function optionalSpecifies the URL for the cell.
You can only use this option if the cell type is link. -
[checked]
String | Function optionalSpecifies whether the check box in the cell is selected or cleared.
You can only use this option if the cell type is checkbox. -
[disabled]
String | Function optionalSpecifies whether the check box in the cell is disabled or enabled.
You can only use this option if the cell type is checkbox. -
[src]
String | Function optionalSpecifies the image source for the cell.
You can only use this option if the cell type is image. -
[click]
String | Function optionalSpecifies the function to run when a user clicks in the cell.
You can only use this option if the cell type is checkbox, link, or image.
-
Examples:
// Creates a text cell containing the word text cell.
crm.grids("0").addCell(2,1,{type:"text", text:"test"});
// Creates a cell containing a link.
crm.grids("0").addCell(2,1,{type:"link", text:"test link", href : "#",
click : function(){console.log("This is a test link")}});
// Creates a cell containing a check box.
crm.grids("0").addCell(2,1,{type:"checkbox", value : "myValue", disabled: true, checked : true,
click : function(){console.log("This is a text check box")}});
// Creates a cell containing an image.
crm.grids("0").addCell(2,1,{type:"image", value : "myValue",
src : "..\\\Themes/Img/default/Bullets/headerhyperlink.gif",
click : function(){console.log("This is a test image")}});
// Illustrates how to use functions to assess what the cell value should be.
// For example, you may need to set the cell value based on the value of another cell in the row.
crm.grids("0").addColumn({index:0 ,columnName: "Is case a high priority issue"});
var value = function() {
var confirmedTrans = crm.getTrans("Choices","High");
var caseStage = this.getCellText(this.currentRow,this.columnNames.indexOf("case_priority")+1);
if (caseStage === confirmedTrans) {
return true;
}
else {
return false;
}
}
crm.grids("0").addCell(2,0,{type:"checkbox", value : "myValue", disabled: true, checked : value,
click : function(){console.log("This is a test check box")}});
addCells
(
-
object
)
-
object
Adds a cell to a grid.
Parameters:
-
object
ObjectSpecifies the cell object to add.
-
index
ObjectSpecifies the index of the column in which to create the cell.
-
type
StringSpecifies the cell type.
You can specify one of the following types:- checkbox - link - text - image
-
[id]
String | Function optionalSpecifies the ID to assign to the cell.
-
[value]
String | Function optionalSpecifies the value to assign to the cell.
-
[text]
String | Function optionalSpecifies the text to include in the cell.
You can only use this option if the cell type is link or text. -
[href]
String | Function optionalSpecifies the URL for the cell.
You can only use this option if the cell type is link. -
[checked]
String | Function optionalSpecifies whether the check box in the cell is selected or cleared.
You can only use this option if the cell type is checkbox. -
[disabled]
String | Function optionalSpecifies whether the check box in the cell is disabled or enabled.
You can only use this option if the cell type is checkbox. -
[src]
String | Function optionalSpecifies the image source for the cell.
You can only use this option if the cell type is image. -
[click]
String | Function optionalSpecifies the function to run when a user clicks in the cell.
You can only use this option if the cell type is checkbox, link, or image.
-
Returns:
Object
Examples:
// Illustrates how to use functions to assess the cell value.
crm.grids("0").addColumn({index:0 ,columnName: "Is case a high priority issue"});
var value = function() {
var confirmedTrans = crm.getTrans("Choices","High");
var caseStage = this.getCellText(this.currentRow,this.columnNames.indexOf("case_priority")+1);
if (caseStage === confirmedTrans) {
return true;
}
else {
return false;
}
}
crm.grids("0").addCells({index:0,type:"checkbox", value : "myValue", disabled: true, checked : value,
click : function(){console.log("This is a test check box")}});
addColumn
(
-
obj
)
-
obj
Adds a column to a grid.
Parameters:
Returns:
Object
Examples:
// Adds a new column named My Test Column at index position 1.
crm.grids().addColumn({index:1,columnName: "My Test Column"});
appendIconToCell
(
-
obj
-
elem
)
-
obj
-
elem
Adds an icon to a field caption.
Parameters:
Returns:
Object
Examples:
// Appends an icon to each cell in the comp_name column of a grid.
crm.grids().rows(":gt(0)",true).cells().column("comp_name").exec(function(index,key){
var rowIndex = $(key).parent().index()+1;
var colDes=this.columnNames.indexOf("case_description")+1;
var text = this.getCellText(rowIndex,colDes); $(key).text(text);
crm.grids().hideColumn("case_stage");
this.appendIconToCell({style:"cursor:pointer; border: solid red 1px",
id:"test"+rowIndex,src:"..\\\Themes/Img/default/Bullets/headerhyperlink.gif",
click : function(){console.log(1)} },$(key))
});
cells
(
-
index
-
isJQuerySelector
)
-
index
-
isJQuerySelector
Gets specified cells.
Parameters:
Returns:
Object
Examples:
// Gets the cell at index position 1.
crm.grids().rows().cells("1")
// Gets all cells.
crm.grids().rows().cells()
// Gets all cells whose index position is greater than 1.
crm.grids().rows.cells(":gt(0)", true)
clearSelection
()
deprecated
Clears selected cells. You can use this method to chain multiple methods on a grid.
Examples:
// Chains multiple methods on a grid.
crm.grids().cells().highlightCell().clearSelection().rows().cells("1").highlightCell("blue")
column
(
-
column
)
-
column
Filters selected cells by column name.
Parameters:
-
column
StringSpecifies the ID of the column by which to filter the selected cells.
Returns:
Object
Examples:
// Filters cells by column whose ID is case_stage.
crm.grids("0 !1 2").rows().column("case_stage").highlightCell()
// Filters cells by column whose ID is oppo_targetclose.
crm.grids().rows().column("oppo_targetclose").highlightCell(false);
columnIndex
(
-
columName
)
-
columName
Gets the index of a given column.
Parameters:
-
columName
StringSpecifies the ID of the column.
Returns:
Number
Examples:
// Gets the index of a column whose ID is comp_name.
crm.grids().columnIndex("comp_name");
exec
(
-
function
)
-
function
Runs a function on each of the selected cells.
Parameters:
-
function
FunctionSpecifies the function.
Returns:
Object
Examples:
// Runs a custom function on the specified cells.
crm.grids().rows().exec(function (index, currentCell) {
crm.log(" the current index is : " + index);
crm.log(" the current row index is : " + $(currentCell).parent().index());
crm.log(" the current cell content is : " + $(currentCell).text());
})
filterWhere
(
-
column
-
operator
-
value
)
-
column
-
operator
-
value
Compares a given value to values contained in cells.
Parameters:
-
column
StringSpecifies the ID of the column containing the cells whose values you want to compare to a given value.
-
operator
StringSpecifies the comparison operator to use. Possible comparison operators are as follows:
-
eq
StringEqual to
-
ne
StringNot equal to
-
lt
StringLess than
-
gt
StringGreater than
-
le
StringLess than or equal to
-
ge
StringGreater than or equal to
-
contains
StringContains text. Only applicable to cells containing string values.
-
between
StringIs between two dates. Only applicable to cells containing date.
In this case, the value to which you compare cell values must be an array containing two dates, for example [date1,date2].
-
-
value
String | Date | NumberSpecifies the value you want to compare to cell values.
Examples:
// Looks for cells in the case_description column whose value contains the word urgent.
// Highlights such cells in red.
crm.grids().rows().filterWhere("case_description","contains","urgent").highlightRow("red");
// Looks for cells in the oppo_forecast column whose value is greater than or equals to 1000.00.
crm.grids().rows().filterWhere("oppo_forecast","ge", 1000.00).highlightRow();
// Looks for cells in the oppo_targetclose column whose value is
// greater than or equals to the date returned by the new Date function.
crm.grids().rows().filterWhere("oppo_targetclose","ge",new Date).highlightRow();
// Looks for cells in the oppo_targetclose column that contain a date which
// falls between one week ago and one week ahead.
var oneWeekAgo = new Date();
oneWeekAgo.setDate(oneWeekAgo.getDate() - 7);
var oneWeekFromNow = new Date();
oneWeekFromNow.setDate(oneWeekFromNow.getDate() + 7);
crm.grids().rows().filterWhere("oppo_targetclose","between",[oneWeekAgo,oneWeekFromNow]).highlightRow()
getCellAttribute
(
-
row
-
column
-
attribute
)
-
row
-
column
-
attribute
Gets an attribute of a given cell.
Parameters:
Returns:
String
Examples:
// Gets the value of the class attribute of the cell located in row 2, column 2.
crm.grids().getCellAttribute(2,2,"class");
getCellDate
(
-
row
-
column
)
-
row
-
column
Gets the date value contained in a given cell.
Parameters:
Returns:
Date
Examples:
// Gets the date contained in the cell located in row 2, column 2.
crm.grids().getCellDate(2,2);
getCellHtml
(
-
row
-
column
)
-
row
-
column
Gets the HTML code contained in a given cell.
Parameters:
Returns:
String
Examples:
// Gets the HTML code contained in the cell located in row 2, column 2.
crm.grids().getCellHtml(2,2);
getCellText
(
-
row
-
column
)
-
row
-
column
Gets the text value contained in a given cell.
Parameters:
Returns:
String
Examples:
// Gets the text contained in the cell located in row 2, column 2.
crm.grids().getCellText(2,2);
grids
(
-
index
)
-
index
Gets one or more grids.
Parameters:
-
index
StringSpecifies the index position of the grids. The first grid on a page starts at index position 0.
On custom entities, you can use the name of the list in this parameter to identify the grid.
Returns:
Object
Examples:
// Gets grid at index position 0.
crm.grids("0");
// Gets all grids.
crm.grids();
// Gets grids at index positions 0 and 1, but not 2.
crm.grids("0 1 !2");
// Gets the grid identified by the CaseList list name.
// This example is only valid for custom entities.
crm.grids("CaseList")
hideColumn
(
-
column
)
-
column
Hides a table column.
Parameters:
-
column
StringSpecifies the ID of the column.
Returns:
Object
Examples:
// Hides a column whose ID is oppo_description.
crm.grids().hideColumn("oppo_description");
highlightCell
(
-
obj
)
-
obj
Highlights currently selected cells. You can also use this method to apply CSS properties to a cell.
Parameters:
Returns:
Object
Examples:
// Highlights the currently selected cell in the default color (yellow).
crm.grids().cells().highlightCell();
// Highlights the currently selected cell in blue.
crm.grids().cells().highlightCell("blue");
// Applies the CSS properties stored in the obj variable to the cell.
var obj = {color:"white","background-color":"blue",'box-shadow': "blue",
'-webkit-box-shadow': "blue",'-moz-box-shadow': "blue", opacity:0.4};
crm.grids().rows().cells().highlightCell(obj);
highlightRow
(
-
obj
)
-
obj
Highlights the row containing the currently selected cells. You can also use this method to apply CSS properties to a row of cells.
Parameters:
Returns:
Object
Examples:
// Highlights the row of currently selected cells in the default color (yellow).
crm.grids().cells().highlightRow();
// Highlights the row of currently selected cells in blue.
crm.grids().cells().highlightRow("blue");
// Applies the CSS properties stored in the obj variable to the row.
var obj = {color:"white","background-color":"blue",'box-shadow': "blue",
'-webkit-box-shadow': "blue",'-moz-box-shadow': "blue", opacity:0.4};
crm.grids().rows(":gt(0)",true).cells().highlightRow(obj);
onGridUpdate
(
-
Specifies
)
-
Specifies
Runs a user-defined JavaScript function when a grid has been updated.
Parameters:
-
Specifies
Functionthe JavaScript function.
Returns:
Object
Examples:
// After a grid has been updated, runs a function that writes the text
// "Grid update detected" to the console.log file.
crm.grids().onGridUpdate(function(){
console.log("Grid update detected")
})
rows
(
-
index
-
isJQuerySelector
)
-
index
-
isJQuerySelector
Gets rows of a grid.
Parameters:
Returns:
Object
Examples:
// Returns the first row of a grid.
crm.grids().rows("1")
// Returns all rows of a grid.
crm.grids().rows()
// Returns all rows of a grid whose index position is greater than 1.
crm.grids().rows(":gt(0)", true)
setCellAttribute
(
-
row
-
column
-
attribute
-
value
)
-
row
-
column
-
attribute
-
value
Sets an attribute of a given cell.
Parameters:
Returns:
Object
Examples:
// Sets the class attribute value of the cell located in row 2, column 2 to ROW1.
crm.grids().setCellAttribute(2,2,"class","ROW1")
setCellHtml
(
-
row
-
column
-
html
)
-
row
-
column
-
html
Sets HTML code in a given cell.
Parameters:
Returns:
Object
Examples:
// Sets HTML code in the cell located in row 2, column 2.
crm.grids().setCellHtml(2,2,'<a href="www.yourlink.com">new Link</a>');
setCellText
(
-
row
-
column
-
text
)
-
row
-
column
-
text
Sets the text value in a given cell.
Parameters:
Returns:
Object
Examples:
// Sets the text value in the cell located in row 2, column 2 to Bigger Description.
crm.grids().setCellText(2,2,"Bigger Description")
showColumn
(
-
column
)
-
column
Shows a hidden column of a table.
Parameters:
-
column
StringSpecifies the ID of the column.
Returns:
Object
Examples:
// Shows a hidden column whose ID is oppo_description.
crm.grids().showColumn("oppo_description");