Class zebkit.data.Matrix
mixed with <zebkit.EventProducer> <zebkit.data.DataModel>
<zebkit.data>

Matrix model class.

Constructor:
zebkit.data.Matrix ([data], [rows], [cols])

Parameters:
  • [data] <Array>

    the given data as two dimensional array

  • [rows] <Integer>

    a number of rows

  • [cols] <Integer>

    a number of columns


Example:
// create matrix with 10 rows and 5 columns
var matrix = zebkit.data.Matrix(10, 5);

matrix.get(0,0);
matrix.put(0,0, "Cell [0,0]");
// create matrix with 3 rows and 5 columns
var matrix = zebkit.data.Matrix([
    [ 0, 1, 2, 3, 4 ],  // row 0
    [ 0, 1, 2, 3, 4 ],  // row 1
    [ 0, 1, 2, 3, 4 ],  // row 2
    [ 0, 1, 2, 3, 4 ],  // row 3
    [ 0, 1, 2, 3, 4 ]   // row 4
]);
// create matrix with 0 rows and 0 columns
var matrix = zebkit.data.Matrix();

// setting value for cell (2, 4) will change
// matrix size to 2 rows and 3 columns
matrix.put(2, 4, "Cell [row = 2, col = 4]");



public <Object> get (row, col)

Get a matrix model cell value at the specified row and column


Parameters:
  • row <Integer>

    a cell row

  • col <Integer>

    a cell column


Returns: <Object>

matrix model cell value

public <Array> getCol (col)

Get the given column data as an array object


Parameters:
  • col <Integer>

    a column


Returns: <Array>

a column data

public <Object> geti (index)

Get a matrix model cell value by the specified index


Parameters:
  • index <Integer>

    a cell index


Returns: <Object>

matrix model cell value

public <Array> getRow (row)

Get the given row data as an array object


Parameters:
  • row <Integer>

    a row


Returns: <Array>

a row data

public chainable insertCol (col, [data])

Insert the column data at the given column


Parameters:
  • col <Integer>

    a column

  • [data] <Array>

    a column data

public chainable insertCols (col, count)

Insert the given number of columns at the specified column


Parameters:
  • col <Integer>

    a starting column to insert

  • count <Integer>

    a number of columns to be added

public chainable insertRow (row, [data])

Insert the row data at the given row


Parameters:
  • row <Integer>

    a row

  • [data] <Array>

    a row data

public chainable insertRows (row, count)

Insert the given number of rows at the specified row


Parameters:
  • row <Integer>

    a starting row to insert

  • count <Integer>

    a number of rows to be added

public chainable put (row, col, obj)

Set the specified by row and column cell value. If the specified row or column is greater than the matrix model has the model size will be adjusted to new one.


Parameters:
  • row <Integer>

    a cell row

  • col <Integer>

    a cell column

  • obj <Object>

    a new cell value

public chainable puti (i, obj)

Set the specified by index cell value. The index identifies cell starting from [0,0] cell till [rows,columns]. If the index is greater than size of model the model size will be adjusted to new one.


Parameters:
  • i <Integer>

    a cell row

  • obj <Object>

    a new cell value

public chainable removeCols (begcol, count)

Remove specified number of columns from the model starting from the given column.


Parameters:
  • begcol <Integer>

    a start column

  • count <Integer>

    a number of columns to be removed

public chainable removeRows (begrow, count)

Remove specified number of rows from the model starting from the given row.


Parameters:
  • begrow <Integer>

    a start row

  • count <Integer>

    a number of rows to be removed

public chainable setCols (cols)

Set the given number of columns the model has to have.


Parameters:
  • cols <Integer>

    a new number of columns

public chainable setRows (rows)

Set the given number of rows the model has to have.


Parameters:
  • rows <Integer>

    a new number of rows

public chainable setRowsCols (rows, cols)

Set the given number of rows and columns the model has to have.


Parameters:
  • rows <Integer>

    a new number of rows

  • cols <Integer>

    a new number of columns

public void sortCol (col, [f])

Sort the given column of the matrix model.


Parameters:
  • col <Integer>

    a column to be re-ordered

  • [f] <Function>

    an optional sort function. The name of the function is grabbed to indicate type of the sorting the method does. For instance: "descent", "ascent".


private <Array> $objs

The multi-dimensional embedded arrays to host matrix data

public <Integer> cols

Number of columns in the matrix model

public <Integer> rows

Number of rows in the matrix model


cellModified

Fired when the matrix model cell has been updated.

 matrix.on("cellModified", function(src, row, col, old) {
    ...
 });

Parameters:
  • src <zebkit.data.Matrix>

    a matrix that triggers the event

  • row <Integer>

    an updated row

  • col <Integer>

    an updated column

  • old <Object>

    a previous cell value

matrixColInserted

Fired when a row has been inserted into the matrix.

 matrix.on("matrixRowInserted", function(src, rowIndex) {
    ...
 });

Parameters:
  • src <zebkit.data.Matrix>

    a matrix that triggers the event

  • rowIndex <Integer>

    a row that has been inserted contains:

matrixColInserted

Fired when a column has been inserted into the matrix.

 matrix.on("matrixColInserted", function(src, colIndex) {
    ...
 });

Parameters:
  • src <zebkit.data.Matrix>

    a matrix that triggers the event

  • colIndex <Integer>

    a column that has been inserted contains:

matrixResized

Fired when the matrix model size (number of rows or columns) is changed.

 matrix.on("matrixResized", function(src, pr, pc) {
     ...
 });

Parameters:
  • src <zebkit.data.Matrix>

    a matrix that triggers the event

  • pr <Integer>

    a previous number of rows

  • pc <Integer>

    a previous number of columns

matrixSorted

Fired when the matrix data has been re-ordered.

 matrix.on("matrixSorted", function(src, sortInfo) {
    ...
 });

Parameters:
  • src <zebkit.data.Matrix>

    a matrix that triggers the event

  • sortInfo <Object>

    a new data order info. The information contains:

     {
        func: sortFunction,
        name: sortFunctionName,
        col : sortColumn
     }