Show:

grids Methods

Methods

addButton
(
  • [options]
)
Object

Adds a button to the column on the right-hand side of a grid.

Parameters:

  • [options] Object optional

    Specifies an object representing the button ID and icon.

    • id String

      Specifies the button ID.

    • image String

      Specifies 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 Function

      Specifies 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
)

Adds a cell to a grid.

Parameters:

  • row Number

    Specifies the row to which to add the cell.

  • column Number

    Specifies the column to which to add the cell.

  • obj Object

    Specifies an object representing the cell.

    • type String

      Specifies the cell type.
      You can specify one of the following types:

              - checkbox
              - link
              - text
              - image
    • [id] String | Function optional

      Specifies the ID to assign to the cell.

    • [value] String | Function optional

      Specifies the value to assign to the cell.

    • [text] String | Function optional

      Specifies the text to include in the cell.
      You can only use this option if the cell type is link or text.

    • [href] String | Function optional

      Specifies the URL for the cell.
      You can only use this option if the cell type is link.

    • [checked] String | Function optional

      Specifies 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 optional

      Specifies 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 optional

      Specifies the image source for the cell.
      You can only use this option if the cell type is image.

    • [click] String | Function optional

      Specifies 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
)

Adds a cell to a grid.

Parameters:

  • object Object

    Specifies the cell object to add.

    • index Object

      Specifies the index of the column in which to create the cell.

    • type String

      Specifies the cell type.
      You can specify one of the following types:

              - checkbox
              - link
              - text
              - image
    • [id] String | Function optional

      Specifies the ID to assign to the cell.

    • [value] String | Function optional

      Specifies the value to assign to the cell.

    • [text] String | Function optional

      Specifies the text to include in the cell.
      You can only use this option if the cell type is link or text.

    • [href] String | Function optional

      Specifies the URL for the cell.
      You can only use this option if the cell type is link.

    • [checked] String | Function optional

      Specifies 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 optional

      Specifies 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 optional

      Specifies the image source for the cell.
      You can only use this option if the cell type is image.

    • [click] String | Function optional

      Specifies 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
)

Adds a column to a grid.

Parameters:

  • obj Object

    Specifies an object that defines the column heading and the index of the column.

    • columnName String

      Specifies the name of the column.

    • index Number

      Specifies the position at which to insert the column.

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
)

Adds an icon to a field caption.

Parameters:

  • obj Object

    Specifies the icon to add in the form of a JSON object.

  • elem Object

    Specifies the cell to which to add the icon.

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
)

Gets specified cells.

Parameters:

  • index String

    Specifies the index of the cell.

  • isJQuerySelector Boolean

    Defines a jQuery selector used to select the cells.

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

Deprecated: This method is no longer supported.

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
)

Filters selected cells by column name.

Parameters:

  • column String

    Specifies 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
)

Gets the index of a given column.

Parameters:

  • columName String

    Specifies 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
)

Runs a function on each of the selected cells.

Parameters:

  • function Function

    Specifies 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
)

Compares a given value to values contained in cells.

Parameters:

  • column String

    Specifies the ID of the column containing the cells whose values you want to compare to a given value.

  • operator String

    Specifies the comparison operator to use. Possible comparison operators are as follows:

    • eq String

      Equal to

    • ne String

      Not equal to

    • lt String

      Less than

    • gt String

      Greater than

    • le String

      Less than or equal to

    • ge String

      Greater than or equal to

    • contains String

      Contains text. Only applicable to cells containing string values.

    • between String

      Is 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 | Number

    Specifies 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
)

Gets an attribute of a given cell.

Parameters:

  • row Number

    Specifies the row number of the cell.

  • column Number

    Specifies the column number of the cell.

  • attribute String

    Specifies the name of the attribute.

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
)

Gets the date value contained in a given cell.

Parameters:

  • row Number

    Specifies the row number of the cell.

  • column Number

    Specifies the column number of the cell.

Returns:

Date

Examples:

   // Gets the date contained in the cell located in row 2, column 2.
   crm.grids().getCellDate(2,2);
getCellHtml
(
  • row
  • column
)

Gets the HTML code contained in a given cell.

Parameters:

  • row Number

    Specifies the row number of the cell.

  • column Number

    Specifies the column number of the cell.

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
)

Gets the text value contained in a given cell.

Parameters:

  • row Number

    Specifies the row number of the cell.

  • column Number

    Specifies the column number of the cell.

Returns:

String

Examples:

   // Gets the text contained in the cell located in row 2, column 2.
   crm.grids().getCellText(2,2);
grids
(
  • index
)

Gets one or more grids.

Parameters:

  • index String

    Specifies 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
)

Hides a table column.

Parameters:

  • column String

    Specifies the ID of the column.

Returns:

Object

Examples:

   // Hides a column whose ID is oppo_description.
   crm.grids().hideColumn("oppo_description");
highlightCell
(
  • obj
)

Highlights currently selected cells. You can also use this method to apply CSS properties to a cell.

Parameters:

  • obj String | Boolean | Object

    Specifies the name of the color in which to highlight the cell.
    When this parameter is empty, the cell is highlighted in yellow by default.
    When this parameter is set to false, it removes the highlight from the cell.

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
)

Highlights the row containing the currently selected cells. You can also use this method to apply CSS properties to a row of cells.

Parameters:

  • obj String | Boolean | Object

    Specifies the name of the color in which to highlight the row of cells.
    When this parameter is empty, the row is highlighted in yellow by default.
    When this parameter is set to false, it removes the highlight from the row.

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
)

Runs a user-defined JavaScript function when a grid has been updated.

Parameters:

  • Specifies Function

    the 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
)

Gets rows of a grid.

Parameters:

  • index String

    Specifies the index position of the row.

  • isJQuerySelector Boolean

    Specifies whether the index parameter value is a jQuery selector.

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
)

Sets an attribute of a given cell.

Parameters:

  • row Number

    Specifies the row number of the cell.

  • column Number

    Specifies the column number of the cell.

  • attribute String

    Specifies the name of the attribute.

  • value String

    Specifies the attribute value.

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
)

Sets HTML code in a given cell.

Parameters:

  • row Number

    Specifies the row number of the cell.

  • column Number

    Specifies the column number of the cell.

  • html String

    Specifies the HTML code.

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
)

Sets the text value in a given cell.

Parameters:

  • row Number

    Specifies the row number of the cell.

  • column Number

    Specifies the column number of the cell.

  • text String

    Specifies the text value.

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
)

Shows a hidden column of a table.

Parameters:

  • column String

    Specifies the ID of the column.

Returns:

Object

Examples:

   // Shows a hidden column whose ID is oppo_description.
   crm.grids().showColumn("oppo_description");

© Copyright Sage Technologies. All rights reserved.