Intersoft WebGrid Documentation
WebGrid Core
See Also Send comments on this topic.
Intersoft WebGrid > Client-side References > WebGrid Core

Glossary Item Box

 WebGrid Core Global Functions

wgGetActiveGrid Description
Gets the currently active grid.

Return Value
object ( WebGrid )

Samples
Determine which grid is having focus currently.

function GetActiveGrid()
{  
        var grid = ISGetObject("WebGrid1");
        grid.SetFocus();  
        alert(wgGetActiveGrid());  
}
wgGetGridById Description
Gets the WebGrid instance by its ID.

Parameters
name ( string )
The WebGrid's ID.

Return Value

object ( WebGrid )

Samples
Gets the WebGrid's instance by ID.

function GetGridName()
{
        var grid = wgGetGridById("WebGrid1");  
        alert(grid.Name);
        // It's highly recommended not to use
        // wgGetGridById method anymore for consistency purpose
        // Please use ISGetObject method for future usage

        var grid = ISGetObject("WebGrid1");  
        alert(grid.Name);
wgGetChildTableByRow Description
Returns the Container element of childtable by specific row and child table name.

Parameters
row ( object - row element )
The HTML row element.
childTblName ( string )
The child table's name.

Return Value

object (WebGridTable)

Samples
Get child table WebGridTable object

function DoSelectRow()
{
        // a simple hiearchical tables
        // Customers -> Orders

        // try to expand the first row first
        // and then use this function
        // in order to use wgGetChildTableByRow
        // the child table needs to be expanded first
        var grid = ISGetObject("WebGrid1");  
        var wgRow = grid.GetSelectedObject().GetRowObject(); 
        var htmlRow = wgRow.GetElement();  
        var chldTbl = wgGetChildTableByRow(htmlRow, "Orders");       
                                                 
        return true;
}
wgGetCellCount Description
Gets the cell's count of the specified row.

Parameters
obj ( object - row element )
The RowElement

Return Value

integer

Samples
Get the number of cells in a table based on a RowElement.

function GetCellCount()
{
        // a simple hiearchical tables
        // Customers -> Orders  
        var grid = ISGetObject("WebGrid1");  
        var wgRow = grid.RootTable.GetRow(0);  
        var htmlRow = wgRow.GetElement();
       
        alert(wgGetCellCount(htmlRow));
       
        return true;
wgGetCellByPosition Description
Returns the cell HTML element based on specified row and position.

Parameters
obj ( object - HTML row element )
The HTML row element
pos ( integer )
The index of the column

Return Value

object (HTML cell element )

Samples
Gets the column's name of the intended cell based on the given HTML RowElement.

function GetCellContents()
{
        // a simple hiearchical tables
        // Customers -> Orders  
        var grid = ISGetObject("WebGrid1");  
        var wgRow = grid.RootTable.GetRow(0);  
        var htmlRow = wgRow.GetElement();
       
        alert(wgGetCellByPosition(htmlRow, 1).innerText);
       
        return true;
wgGetCellByName Description
Returns the cell HTML element based on the specified row and column's name.

Parameters
obj ( object - row element )
The HTML RowElement
name ( string )
The column's name

Return Value

object (cell element )

Samples
Gets the column's name of the given row element and also the column's name.

function GetCellContents()
{
        // a simple hiearchical tables
        // Customers -> Orders  
        var grid = ISGetObject("WebGrid1");  
        var wgRow = grid.RootTable.GetRow(0);  
        var htmlRow = wgRow.GetElement();
       
        alert(wgGetCellByName(htmlRow, "Country").innerText);
       
        return true;
wgGetCellPosByName Description
Returns the cell's position by column's name.

Parameters
obj ( object - row element )
The HTML row element

cell ( string )

The column's name

Return Value

integer

Samples
Gets the cell's position in the table.

function GetCellContents()
{
        // a simple hiearchical tables
        // Customers -> Orders  
        var grid = ISGetObject("WebGrid1");  
        var wgRow = grid.RootTable.GetRow(0);  
        var htmlRow = wgRow.GetElement();
       
        // return null
        alert(wgGetCellPosByName(htmlRow, "CustomerID"));
       
        return true;
wgGetRowByPosition Description
Returns the row based on specified table and position.

Parameters
table ( object - table element )
The HTML table element object
pos ( integer )
The row index position

Return Value

object ( row element )

Samples
Gets the HTML row element.
function GetRowElement()
{
  var grid = ISGetObject("WebGrid1");  
  var htmlTbl = grid.RootTable.GetElement(WG40.BODY, WG40.HTMLTABLE);  
  var htmlRowElm = wgGetRowByPosition(htmlTbl, 0);  
  alert(htmlRowElm.type);  
  return true;
wgGetRowByPositionExact Description
Gets the row based on specified exact position indexed by WebGrid internal row's position.

Parameters
table ( object )
The table element
pos ( integer )
The row index
startPos ( integer )
The starting row index (optional)

Return Value

object (row element)

Samples
the sample shows how to get row by position exact

// get the grid Object.
var grid = ISGetObject("WebGrid1");

// get HTML body of the table element.
var tblElm = grid.GetRootTable().GetElement(WG40.BODY,WG40.HTMLTABLE);

// get row by position exact.
var row = wgGetRowByPositionExact(tblElm,1,1);

wgGetRootRow Description
Gets the root/first row of a ColumnSet rows or PreviewRow.

Parameters
row ( object - row element )
The row element

Return Value

object (row element)

Samples
The sample shows how to get Gets the root/first row of a columnset rows or previewrow.

// get the grid Object.
var grid = ISGetObject("WebGrid1");

//get row element.
var rowElm = grid.GetSelectedObject().GetRowObject().GetElement();

// get the root of the rows.
var rootRow = wgGetRootRow(rowElm);
wgGetColNameByCell Description
Gets the column's name based on specified cell.

Parameters
cell ( object - cell element)
The cell element

Return Value

string

Samples
The sample shows how to get the column name with using cell element.

// get the grid Object.
var grid = ISGetObject("WebGrid1");

//get the row Element from the selected object.
var rowElm = grid.GetSelectedObject().GetRowObject().GetElement();

//get the string column name with using cell element.
var columnName = wgGetColNameByCell(rowElm.cells[3]);

wgGetSelectedObjectFromEvent Description
Gets the wgSelectedObject from event information.

Parameters
evnt ( object )
The event object

Return Value

object (SelectedObject)

Samples
The sample shows how to get the selected object from window.event.

//get the selected object from window. event.
var obj = wgGetSelectedObjectFromEvent(window.event);

//get the selected object from window. event.
var obj = wgGetSelectedObjectFromEvent(window.event);

//get the selected object from window. event.
var obj = wgGetSelectedObjectFromEvent(window.event);
wgIsColumnSetRow Description
Determines whether the specified row is a ColumnSet row.

Parameters
row ( object - row element )
The row element

Return Value

boolean

Samples
The sample shows wgIsColumnSetRow is false when the selected row is not in a column set.

//get the object of the grid
var grid = ISgetObject("WebGrid1");

//get the selected row element
var rowElm = grid.GetSelectedObject().GetRowObject().GetElement();

//check whether the row is a ColumnSet row or not.
var bool = wgIsColumnSetRow(rowElm) ;
wgGetPreviewRow Description
Gets the row html element of a PreviewRow object.

Parameters
row ( object - row element)
The row element

Return Value

object (row element)

Samples
The sample shows how to get the html row element of a selected preview row.

// get the grid object.
var grid = ISGetObject("WebGrid1");

// get the selected object row element.
var rowElm = grid.GetSelectedObject().GetRowObject().GetElement();

// get the html of the preview row.
var row = wgGetPreviewRow(rowElm)
wgGetPreviewRowCell Description
Gets the cell HTML element which contains data of the preview row.

Parameters
row ( object - row element )
The row element

Return Value

object (row element)

Samples
The sample shows how to get the cell element from row of the preview row

//get grid object
var grid = ISGetObject("WebGrid1");

//get the row element of the selected object
var rowElm = grid.GetSelectedObject().GetRowObject().GetElement();

//get the preview row element
var prevrow = wgGetPreviewRow(rowElm);

//get the preview cell element
var prevcell = wgGetPreviewRowCell(prevrow);
wgIsValidCell Description
Gets the valid cell.

Parameters
c ( object )
The cell element

Return Value

boolean

Samples
The sample shows how to get to know whether the first cell is valid or not.

//get the grid object.
var grid = ISGetObject("WebGrid1");

//get the row element.
var rowElm = grid.GetSelectedObject().GetRowObject().GetElement();

//get the first cell element.
var cellElm = rowElm.cells[1];

//get to know whether the cell element is valid or not.
var cellbool =  wgIsValidCell(cellElm);
wgIsValidClickableCell Description
Gets the valid clickable cell.

Parameters
c ( object - cell element)
the cell element

Return Value

boolean

Samples
The sample shows whether the cell is valid clickable.

// get the grid Object.
var grid = ISGetObject("WebGrid1");

// get HTML row element.
var rowElm = grid.GetSelectedObject().GetRowObject().GetElement();

//get the status whether cell is valid clickable or not.
wgIsValidClickableCell(rowElm.cells[1])

wgIsValidRow Description
Gets the valid row

Parameters
tr ( object - row element)
The row element

Return Value

boolean

Samples
The sample shows how to get to know whether the row is valid.

// get the grid Object.
var grid = ISGetObject("WebGrid1");

// get HTML row element.
var rowElm = grid.GetSelectedObject().GetRowObject().GetElement();

//get to know whether the row is valid or not
wgIsValidRow(rowElm)

wgGetPreviewRowParent Description
Gets the row html element of the parent row of specified preview row

Parameters
pr ( object - row element )
The row element

Return Value

object (row element)

Samples
The sample shows how to get the parent of the preview row.

// get the grid Object.
var grid = ISGetObject("WebGrid1");

// get HTML row element.
var rowElm = grid.GetSelectedObject().GetRowObject().GetElement();

//get the parent of the preview row
wgGetPreviewRowParent(rowElm)

wgIsSameRow Description
Determines whether row1 and row2 is in one DataRow.

Parameters
row1 ( object - row element )
The row element
row2 ( object - row element )
The row element

Return Value

boolean

Samples
the sample compares 2 row elements.

// get the grid Object.
var grid = ISGetObject("WebGrid1");

// get HTML row element.
var rowElm = grid.GetSelectedObject().GetRowObject().GetElement(); 

//get the status of comparing the two columnset row elements.
var isbool = wgIsSameRow(rowElm,wgGetRowByPositionExact(tblElm,1))

wgIsSameColumnSetRow Description
Determines whether the row1 and row2 is in the same ColumnSet rows.

Parameters
row1 ( object - row element )
The row element
row2 ( object - row element )
The row element

Return Value

boolean

Samples
The sample compares 2 columnset row elements.

// get the grid Object.
var grid = ISGetObject("WebGrid1");

// get HTML row element.
var rowElm = grid.GetSelectedObject().GetRowObject().GetElement(); 

//get the status of comparing the two columnset row elements.
var isbool = wgIsSameColumnSetRow(rowElm,wgGetRowByPositionExact(tblElm,1));

wgIsRecordRow Description
Determines whether the specified row is a record row

Parameters
row ( object - row element )
The row element

Return Value

boolean

Samples
The sample shows how to know whether the first cell is clickable or not

//get the grid object
var grid = ISGetObject("WebGrid1");

//get the row element
var rowElm = grid.GetSelectedObject().GetRowObject().GetElement()

//get the first cell status valid or not
var bool =  wgIsRecordRow(rowElm);
wgGetHierRecord Description
Gets the child's row element from a specified row of hierarchical grid

Parameters
row ( object - row element )
The row element

Return Value

object ( row element)

Samples
This sample shows how to get the child's row element of the hierarchical grid.

function doRowSelect(controlId, tblName, rowIndex, rowEl)

    var rec = wgGetHierRecord(rowEl);
}
  
wgGetRowByGroup Description
Gets the group's row element

Parameters
tb ( object - table element )
The table element
groupIdx ( integer )
The group index
groupPos ( integer )
The position of the group
startTR ( integer )
The start row index to search (optional)

Return Value

object (row element)

Samples
The sample shows how to get the first group's row element

function doButtonClick()

    //get the grid object
    var grid = ISGetObject("WebGrid1"); 

    //make sure the grid is grouped
    if (grid.RootTable.GroupedColumns.length > 0) 
    { 
        //get the first group row element
        var firstGroupRow = wgGetRowByGroup(grid.RootTable.GetElement(WG40.BODY,WG40.HTMLTABLE),0,0); 

        alert(firstGroupRow.innerText); 
    }
}
wgIsFilterRow Description
Determines whether or not the row element is filter row.

Parameters
row ( object - row element )
The row element

Return Value

boolean

Samples
This sample shows how to determine whether or not a row is a filter row.

function doRowSelect(controlId, tblName, rowIndex, rowEl)

    var flag = wgIsFilterRow(rowEl);
    return true;
}
wgRemoveRow Description
Removes a row from table element.

Parameters
table ( object - table element )
The table element
row ( object - row element )
The row element

Return Value

void

Samples
The sample shows how to remove the selected row.

function doRowSelect(controlId, tblName, rowIndex, rowEl)

    //get the grid object of the selected row
    var grid = ISGetObject(controlId); 

    //get the table object of the selected row
    var table = grid.Tables[tblName].GetElement(WG40.BODY,WG40.HTMLTABLE); 

    //remove the selected row
    wgRemoveRow(table,rowEl);     

    return true;
}
wgGetGridByElement Description
Gets the grid object of HTML element.

Parameters
el ( object - HTML element )
The HTML element

Return Value

object (WebGrid)

Samples
The samples shows how to get the WebGrid object from the a cell element

function doRowSelect(controlId, tblName, rowIndex, rowEl)
{
    //get the cell element of the selected row
    var cell = wgGetCellByName(rowEl, "Address");

    //get the grid object from the cell element
    var grid = wgGetGridByElement(cell);

    alert(grid.Id);

    return true;
}
wgGetTableByElement Description
Gets the table object of table element.

Parameters
el ( object - table element )
The table element

Return Value

object (WebGridTable)

Samples
The samples shows how to get the WebGridTable object from a table element.

function doRowSelect(controlId, tblName, rowIndex, rowEl)
{
    //get the grid object
    var grid = ISGetObject(controlId);

    //get the table element
    var tbl = grid.Tables[tblName].GetElement(WG40.BODY,WG40.HTMLTABLE);

    //get the table object
    var tblEl = wgGetTableByElement(tbl);

    return true;
}
wgGetColumnByElement Description
Gets the column object of column element.

Parameters
el ( object - column element )
The column element

Return Value

object (WebGridColumn)

Samples
The samples shows how to get the WebGridColumn object from the a column element.

function doRowSelect(controlId, tblName, rowIndex, rowEl)
{
    //get the grid object
    var grid = ISGetObject(controlId);

    //get the table object
    var tbl = grid.Tables[tblName];

    //get the row object
    var row = tbl.GetRow(0);

    //get the cell element
    var cell = row.GetCell(0).GetElement();

    //get the WebGridColumn object 
    var col = wgGetColumnByElement(cell);

    return true;
}
wgGetCellByElement Description
Gets the cell object of cell element.

Parameters
el ( object - cell element )
The cell element

Return Value

Object (WebGridCell)

Samples
The samples shows how to get the WebGridCell object from the a cell element.

function doRowSelect(controlId, tblName, rowIndex, rowEl)
{
    //get the cell element of the selected row
    var cell = wgGetCellByName(rowEl, "Address");

    //get the WebGridCell object from the cell element
    var cellObj = wgGetCellByElement(cell);
    return true;
}
wgGetRowByElement Description
Gets the WebGridRow object of the row element.

Parameters
el ( object - row element )
The row element

Return Value

object (WebGridRow)

Samples
The samples shows how to get the WebGridRow object from the a row element.

function doRowSelect(controlId, tblName, rowIndex, rowEl)
{
    //get the row object
    var rowObj = wgGetRowByElement(rowEl);
    return true;
}

See Also

©2012 Intersoft Solutions Corp. All Rights Reserved.