Data Table
The DataTable object provides a way to display data in a grid format.
Data Table Object
Property |
Description |
ColumnCount |
Number of columns in th table. |
Columns |
Returns a copy of the Columns (DataTableColumn) in the Datatable. Modifying the contents of this list will not update the DataTable |
Data |
A list of dictionaries that represent the rows of data in the DataTable. Dictionary keys are used by the Column Field property to align the data to the table columns. Note that the data is not an intrinsic part of the data table. The data remains a separate object. The data property will need to be set on every change. |
HorizontalScrollOffset |
The position of the horizontal scroll. Set to update the scroll position |
RowCount |
Number of rows in the table. |
Rows |
Returns a copy of the Rows (DataTableRow) in the Datatable. Modifying the contents of this list will not update the DataTable |
SelectedItems |
List of DataTableRows that are currently selected. Set this property with the relevant rows to update the selection in the DataTable programmatically. |
SelectionMode |
The row selection mode of the DataTable. Uses the DataTableSelectionMode enum. Options: DataTableSelectionMode.Multiple DataTableSelectionMode.None -
DataTableSelectionMode.Single
|
VerticalScrollOffset |
The position of the vertical scroll. Set to update the scroll position. |
Method |
Description |
AddColumn(DataTableColumn) |
Adds a column to the DataTable using a DataTableColumn object. |
AddRow(DataTableRow) |
Adds a row at the position specified on the new row. |
AddRow(Dictionary{ColumnName:Value}) |
Adds a new row using the data given in the dictionary. |
ClearColumns() |
Clears all columns. |
ClearRows() |
Clears all rows. |
ClearSelection() |
Unselects all rows. |
GetColumn(Int ColumnIndex) |
Get the column instance at the specified column index. |
GetColumn(String ColumnName) |
Get the column instance by the specified field. |
GetRow(Int) |
Returns the row at the given index. |
GetValue(Int RowNumber, String ColumnName) |
Returns the object or variable stored in the specified row and column. |
MoveRow(Int FromRow, Int ToRow) |
Moves the position of a row located at the FromRow index to the ToRow index. |
RemoveColumn(String ColumnName) |
Removes a column from the table using the Column Name. |
RemoveRow(Int RowNumber) |
Removes the row at the specified index. |
RemoveRow(DataTableRow) |
Removes the specified row object. |
UpdateRow(Int RowNumber, DataTableRow) |
Replaces the row at a given index with a new row. |
UpdateRow(Int RowNumber, Dict NewValues) |
Updates a row at a given index with values from th NewValues dictionary. |
Event |
Description |
ScrollPositionChanged |
Event runs when the scroll is moved. |
SelectionChanged |
Event runs when th selection is changed. |
DataTableColumn
Property |
Description |
Field |
Internal name of the column |
Header |
The visible name of the column, shown in the first row of the DataTable. |
Index |
Position/order of the column. |
Mode |
Options: - ColumnFitMode.Content (Sizes columns to fit contents)
- ColumnFitMode.None (Doesn't size to fit contents)
- ColumnFitMode.Stretch (Divide the free space of the DataTable between all stretch columns)
|
Width |
Width of the column in pixels. |
DataTableRow
Property |
Description |
Row |
Row Index |
Values |
Dictionary of values stored in th row. |
Method |
Description |
Invalidate() |
Triggers and updates the row display. |
UpdateCell(String Field, Object Value) |
Updates a cell in the row if the field exists and the value is different. Once all updates to the row are completed, Invalidate() should be called to update the display. |
View Example
{
"$type":"DataTable",
"Height": "200",
"Width":"350",
"X":0,
"Y":0,
"Columns":[
{
"$type":"DataTableColumn",
"Index":0,
"Header":"Index",
"Field":"Index",
"Width": "100"
},
{
"$type":"DataTableColumn",
"Index":1,
"Header":"Name",
"Field":"Name",
"Width": "100"
},
{
"$type":"DataTableTextColumn",
"Index":2,
"Header":"Volume (L)",
"Field":"Volume",
"Width":"200"
}
],
"Data":[
{
"Index":"0",
"Name": "Filler 1",
"Volume": "512"
},
{
"Index":"1",
"Name": "Filler 2",
"Volume": "307"
},
{
"Index":"2",
"Name": "Filler 3",
"Volume": "16"
}
]
}
Python Example
from Omniview.Python import *
headers = ['Name','Address','Email','']
fields = ['Name','Address','Email','Action']
# Create Data Table
myDataTable = DataTable()
myDataTable.Name = 'myDataTable'
myDataTable.Width = 550
myDataTable.Height = 200
myDataTable.X = 10
myDataTable.Y = 100
# Create Data Table Columns
for i in range(len(headers)-1):
header = headers[i]
field = fields[i]
myColumn = DataTableTextColumn()
myColumn.Header = header
myColumn.Field = field
myColumn.Mode = 1
myDataTable.Add_Column(myColumn)
myColumn = DataTableObjectColumn()
myColumn.Header = ''
myColumn.Field = 'Action'
myColumn.Mode = 0
myColumn.Width = 102
myDataTable.Add_Column(myColumn)
# Add data table to View
Omniview.Windows[0].Content.AddViewObject(myDataTable)
myDataTable = Omniview.Windows[0].Content.Get_Object('myDataTable')
# Populate Rows with data
# Create example action button
actionButton = Button()
actionButton.Text = 'Send Email'
actionButton.Width = 100
actionButton.Height = 20
actionButton.MouseLeftButtonUpExpression = Expression("print(Omniview.Windows[0].Content.Get_Object('myDataTable').SelectedItems[0].Values)")
# Create example data button
values =[ {
"Name":'Arthur McAdmin',
'Address':'72 Client St, Springfield, 9955',
'Email':'Admin@example.com',
'Action':actionButton
},
{
"Name":'Plant Manager',
'Address':'123 Industrial Ave, ',
'Email':'BestCustomer@example.com',
'Action':actionButton
},
{
"Name":'Lead Engineer',
'Address':'123 Industrial Ave, ',
'Email':'Engineering@example.com',
'Action':actionButton
}
]
myDataTable.Data = value
See Also
Views
View Object Overview