Class: DataView

DataView

DataView is a View on top of DataTable , all CRUD operations on datatable are done thru DataView .

new DataView(datacolumns, datarows)

Parameters:
Name Type Description
datacolumns Array.<pear.data.Column> Array of pear.data.Column
datarows Array.<Object.<string, *>>
Source:
Example
var columns = [
  new pear.data.Column("Order No",'orderno','orderno',75,
        pear.data.Column.DataType.NUMBER),
  new pear.data.Column("Item",'item','item',115,
        pear.data.Column.DataType.TEXT),
  new pear.data.Column("Unit Price",'unitprice','unitprice',
        75,pear.data.Column.DataType.NUMBER),
  ...
  ...
];

// that datarow object property name is identical to the Column Id
var data = [
  {orderno:1,item:'Samsung-Galaxy',unitprice:200,...,...,...},
  {orderno:2,item:'Iphone',unitprice:200,...,...,...},
  {orderno:3,item:'Kindle-Fire',unitprice:200,...,...,...},
  ...
  ...
  ...
];

   // Create DataView Object
   var dataView = new pear.data.DataView(columns,data);

Extends

  • goog.events.EventTarget

Members

<static> EventType :string

DataView Events
Type:
  • string
Properties:
Name Type Default Description
DATAVIEW_CHANGED String dataview-changed When DataView is changed - like row added ,removed or updated
DATASOURCE_CHANGED String datasource-changed When DataView is initialized - this is primarily when DataRows are changed
ROWVIEW_CHANGED String rowview-changed This event is fired for each Row Added/Updated/Removed Note : not yet implemented
ROWVIEW_SELECT String rowview-select This event is fired when a rowview is added to "rowview select" collection
ROWVIEW_UNSELECT String rowview-unselect This event is fired when a rowview is removed from "rowview select" collection
DATAROW_CHANGED String datarow-changed This event is fired for each Row Added/Updated/Removed
Source:

<static> FilterType :number

Type:
  • number
Properties:
Name Type Default Description
LIKE number 1
EQUAL number 2
GREATER_THAN number 3
LESS_THAN number 4
BETWEEN number 5
Source:

Methods

addColumnFilter(dataColumn, filter)

Add a filter expression for a datacolumn , currently grid support one filter expression per column
Parameters:
Name Type Description
dataColumn pear.data.Column
filter string
Source:

addDataRow(datarow)

Add a DataRow
Parameters:
Name Type Description
datarow Object.<string, *>
Source:

applyFilter(fnFilter, op_context) → {Array.<pear.data.RowView>}

Apply filter on DataView , it uses http://goo.gl/USG5xs
Parameters:
Name Type Description
fnFilter function
op_context Object
Source:
Returns:
Type
Array.<pear.data.RowView>
Example
var filteredRows = dv.applyFilter(filterfn,this);
 dv.setDataRowViews(filteredRows);
...
...
var filterfn = function(rowview) {
   var columns = dv.getDataColumns();
   var match = true;
   goog.array.forEach(columns,function(column){
     var rowdata= rowview.getRowData();
     if (column.filter && column.filter.length > 0){
       var str;
       var filter = String(column.filter);
       if (column.formatter){
         str = String(column.formatter(rowdata[column.id]));
       }else{
         str = String(rowdata[column.id]);
       }

       if (str.toLowerCase().indexOf(filter.toLowerCase()) >=0) {
         match = match && true;
       }else{
         match = match && false;
       }
     }else{

     }
   },this);
   return match;
 };

clearColumnFilter(dataColumn)

remove filter expression from the column
Parameters:
Name Type Description
dataColumn pear.data.Column
Source:

clearSelectedRowViews()

Clear the Selected RowView collection
Source:

<protected> disposeInternal()

Source:

getColumnFilter(dataColumn) → {string}

get fitler expression for the column
Parameters:
Name Type Description
dataColumn pear.data.Column
Source:
Returns:
Type
string

getColumns() → {Array.<pear.data.Column>}

get All Columns info
Source:
Returns:
Type
Array.<pear.data.Column>

getDataRowById(rowid) → {Object.<string, *>}

Get DataRow by RowView Id i.e RowId
Parameters:
Name Type Description
rowid string
Source:
Returns:
Type
Object.<string, *>

getDataRows() → {Array.<Object.<string, *>>}

Get DataRows
Source:
Returns:
Type
Array.<Object.<string, *>>

getDataRowViewCount() → {number}

Get DataRowView count this could be different than DataRow Count e.g if you set Filter on Grid , DataRowView count will return all the rows which are result of filter being applied where as , getDataRowCount will return all rows available
Source:
Returns:
Type
number

getDataRowViews() → {Array.<pear.data.RowView>}

get DataRow View
Source:
Returns:
Type
Array.<pear.data.RowView>

getGrid() → {pear.ui.Grid}

Return the instance of Grid on which DataView is used There can be one Grid per instance of DataView
Source:
Returns:
Type
pear.ui.Grid

getRowCount() → {number}

Get the row count of Actual datasource (DataRows in DataTable)
Source:
Returns:
Type
number

getSelectedRowViewsIds() → {?Array.<string>}

Get Id's of Selected RowViews
Source:
Returns:
Type
?Array.<string>

isDatasourceChanged() → {boolean}

Source:
Returns:
Type
boolean

removeDataRow(id)

Remove a DataRow
Parameters:
Name Type Argument Description
id string <nullable>
Source:

resetDatasourceChangeIndicator()

Source:

selectRowView(rowview, select)

Select a RowView , this method will fire ROWVIEW_SELECT and ROWVIEW_UNSELECT event
Parameters:
Name Type Description
rowview pear.data.RowView
select boolean
Source:
Fires:
  • pear.data.DataView.EventType#event:ROWVIEW_SELECT
  • pear.data.DataView.EventType#event:ROWVIEW_UNSELECT

setColumns(dc)

set column info of dataview
Parameters:
Name Type Description
dc Array.<pear.data.Column>
Source:

setDataRows(data)

Set DataRows , this will fire DataSourceChange and DataViewChange event
Parameters:
Name Type Description
data Array.<Object.<string, *>>
Source:
Fires:
  • pear.data.DataView.EventType#event:DATASOURCE_CHANGED
  • pear.data.DataView.EventType#event:DATAVIEW_CHANGED
Example
var data = [
  {orderno:1,item:'Samsung-Galaxy',unitprice:200,...,...,...},
  {orderno:2,item:'Iphone',unitprice:200,...,...,...},
  {orderno:3,item:'Kindle-Fire',unitprice:200,...,...,...},
  ...
  ...
  ...
];

 // Set DataRows
 myDataView.setDataRows(data);

setDataRowViews(rowViews)

Set DataView
Parameters:
Name Type Description
rowViews Array.<pear.data.RowView>
Source:

setGrid(grid)

this should not be used to set a Grid , this is used internally by grid to set itself when DataView is assigned to Grid
Parameters:
Name Type Description
grid pear.ui.Grid
Source:
See:

sort(sortDirection, columnid)

Basic Sort
Parameters:
Name Type Description
sortDirection pear.ui.Grid.SortDirection SortDirection
columnid string pear.data.Column.id
Source:

updateDataRow(uniqueid, datarow)

Update a DataRow
Parameters:
Name Type Description
uniqueid string
datarow Object.<string, *>
Source: