DataTable Viper Module
Viper Methods
Global Viper Method | Description |
---|---|
DataTable.Aggregate Viper Method | Aggregates the given datatable on the given column, grouped by the given columns. |
DataTable.Append Viper Method | Appends data from the given datatables to the source table, using the specified options. |
DataTable.Clone Viper Method | Return a clone of the given datatable. |
DataTable.Columns.Add Viper Method | Adds the a new column to the datatable. |
DataTable.Columns.Count Viper Method | Returns the number of columns in the datatable. |
DataTable.Columns.Exists Viper Method | Returns true if the column name exists, false otherwise. |
DataTable.Columns.GetName Viper Method | Gets the column name by its index. |
DataTable.Columns.GetNames Viper Method | Returns a datatable containing all the column names in this datatable. |
DataTable.Columns.GetOrdinal Viper Method | Returns the ordinal of the given column name. |
DataTable.Columns.GetType Viper Method | Returns the type of the given column. |
DataTable.Columns.Remove Viper Method | Removes an existing column from the datatable. |
DataTable.Columns.Rename Viper Method | Renames the column name. |
DataTable.Compute Viper Method | Computes a value based on a given expression after the datatable has been filtered by the given filter. The notation of the expression and filter parameter are described in the Microsoft documentation of the System.Data.DataColumn.Expression property. |
DataTable.Create Viper Method | Creates a new datatable containing a single row where the column names and the values are determined by the parameters. |
DataTable.CreateEmpty Viper Method | Create an empty datatable without columns and rows. |
DataTable.CreateForInputData Viper Method | Creates an empty datatable for use as input for the given macro parameter |
DataTable.Distinct Viper Method | Returns a datatable with a single column, containing all the distinct values in the column. |
DataTable.FindOne Viper Method | Finds a single row and returns the row number (-1 if not found). |
DataTable.GetBytes Viper Method | Gets the binary data (byte array) from a Binary Data-formatted DataTable. |
DataTable.GetValue Viper Method | Gets the value of a column in the first row of the given DataTable. |
DataTable.IsValid Viper Method | Determines whether the specified data table is valid (i.e. not closed and has at least one field). |
DataTable.Join Viper Method | Joins the datatables into one. |
DataTable.Rows.Add Viper Method | Adds a new row to the datatable with the given values. |
DataTable.Rows.Count Viper Method | Gets the number of rows in the datatable. |
DataTable.Rows.InsertAt Viper Method | Inserts a new row at given row index in the datatable. |
DataTable.Rows.Remove Viper Method | Removes the rows based on the given expression. |
DataTable.Rows.RemoveAll Viper Method | Removes all the rows in the datatable. |
DataTable.Rows.RemoveAt Viper Method | Removes the given row numbers from the datatable. |
DataTable.Rows.RemoveDuplicates Viper Method | Removes duplicate rows from the datatable. |
DataTable.Rows.RemoveRange Viper Method | Removes rows from the datatable, starting from the startIndex. |
DataTable.Search Viper Method | Searches the specified data table using the given expression. |
DataTable.SetValue Viper Method | Sets the value on the row and column of the given datatable. |
DataTable.SimpleFormat Viper Method | Formats the given datatable rows and returns a table. |
DataTable.SimpleFormatRow Viper Method | Formats a single row in the given datatable and returns a string using the given formatting parameters. |
DataTable.Sort Viper Method | Sorts the specified datatable. |
DataTable.ToXml Viper Method | Gets an XML representation of the DataTable. |
DataTable.Transpose Viper Method | Return the transposed version of the given datatable. |
Examples
Game Of Life
This example contains an implementation of the Game Of Life entirely written in SXML. On every form post a new generation in the game of life is calculated and send back to the client. The current state of the game is stored in a hidden 'world' input element and send back and forth between server and client. The initial state of the game is defined in the body of the item and read using the itemdata viper.
The example relies heavily on buffers and the se:for macro to implement the game logic. Please note that this example is just a proof of concept that it's possible to implement fairly complex business logic in SXML. In the real world the game logic would be implemented in a custom macro in order to achieve the best performance.
About Game Of Life
The Game Of Life is a 'cellular automaton', and was invented by Cambridge mathematician John Conway. It consists of a collection of cells which, based on a few mathematical rules, can live, die or multiply. Depending on the initial conditions, the cells form various patterns throughout the course of the game.
For more information see http://www.bitstorm.org/gameoflife/.
Smartsite SXML | Copy Code |
---|---|
<se:buffer scope="page" name="initialworld" trim="both"> ........ O.O..... .OO..... .O...... ........ ........ ........ ........ </se:buffer> <form method="post"> <!--// get world from form post --> {buffer.set(worldData, string.isempty(request.form.list(world), buffer.get(initialworld, page)))} {buffer.set(generation, convert.toint(string.isempty(request.form.list(generation), 0)) + 1)} {buffer.set(world, string.split($worldData, char.crlf()))} <se:text whitespace="remove"> {buffer.set(newWorld, string.split(buffer.get(initialworld, Page), char.crlf()))} <!--// suppress output --> <se:text resulttype="none"> <!--// remove rem and empty lines from world --> {datatable.delete($world, "col1 = '' or col1 like '!*'")} <!--// empty new world --> {datatable.delete($newWorld, "")} </se:text> <!--// calculate next generation --> <se:for from="1" to="{datatable.getrowcount($world)}" resulttype="none"> {buffer.set(line, datatable.getvalue($world, this.index(), 1))} {buffer.set(newLine, "")} <se:for from="1" to="{string.length($line)}"> <!--// calculate new value for each cell --> {buffer.set(x, this.index()-1)} {buffer.set(y, this.parent.index())} {buffer.set(populated, string.substring($line, $x, 1) == "O")} {buffer.set(neighbors, 0)} <se:if expression="$populated"> <!--// exclude myself from neighbors --> {buffer.set(neighbors, -1)} </se:if> <!--// find neighbors--> <se:for from="{math.max($y-1, 1)}" to="{math.min($y+1, datatable.getrowcount($world))}"> {buffer.set(currentLine, datatable.getvalue($world, this.index(), 1))} <se:for from="{math.max($x-1, 0)}" to="{math.min($x+1, string.length($currentLine) - 1)}"> <se:if expression="string.substring($currentLine, this.parent.index(), 1) == 'O'"> {buffer.set(neighbors, $neighbors+1)} </se:if> </se:for> </se:for> <!--// rules Game Of Life --> {buffer.set(newCell, ".")} <se:if expression="$populated AND $neighbors == 2 || $neighbors == 3"> {buffer.set(newCell, "O")} </se:if> {buffer.set(newLine, string.concat($newLine, $newCell))} </se:for> {datatable.add($newWorld, $newLine)} </se:for> <!--// replace world --> {buffer.set(world, $newWorld)} </se:text> {buffer.set(newWorldData, "")} <!--// render generation --> <b>Generation {buffer.get(generation)}</b> <se:text whitespace="remove"> <pre style="font-size:7"> <se:format inputdata="world"> <se:rowformat> {this.field(1)}<br /> <!--// serialize world --> {buffer.set(newWorldData, string.concat($newWorldData, this.field(1), char.crlf()))} </se:rowformat> </se:format> </pre> </se:text> <input type="hidden" name="world" value="{buffer.get(newWorldData)}" /> <input type="hidden" name="generation" value="{buffer.get(generation)}" /> <input type="submit" value="Next Generation" /> </form> |
Random DataTable Example
This example generates a datatable with random data. The number of rows in the datatable can be controlled by setting the to-parameter of the For macro. The word count for the text field can be controlled by changing the value for the wrdcnt buffer.
Smartsite SXML | Copy Code |
---|---|
<se:hidden rem="generate a datatable with random values"> {math.setrandomseed(1, rem="set seed to ensure data is identical for each rendering")} {buffer.set(dt, datatable.createempty(Row,Number,Date,Text))} {buffer.set(wordcnt, 20, rem="max word count for random text")} <se:for from="1" to="100" rem="to-parameter is the rowcount for the output datatable"> {buffer.set(rnd, math.random($wordcnt))} <se:lorem save="lorem" rem="calculate random text" unitcount="{buffer.get(wordcnt)}" unittype="word" skiprows="{buffer.get(rnd)}" maxrows="{math.random($wordcnt-$rnd)}" rowformat="{this.field(1)}" rowdelimiter=" " /> {datatable.rows.add($dt ,this.index() , math.random(1000) , datetime.addseconds( datetime.addhours(convert.todate('2010-01-01T00:00:00'), math.random(100000)-50000),math.random(10000)-5000) , $lorem )} </se:for> </se:hidden> <se:format inputdata="dt" rem="render datatable as a html table"> <se:rowformat> <se:colformat><td>{this.field()}</td></se:colformat> <se:rowresult>{char.tab()}<tr>{this.rowresult()}</tr>{char.crlf()}</se:rowresult> </se:rowformat> <se:captionformat match="first"> <se:colformat><th>{this.colname()}</th></se:colformat> <se:rowresult>{char.tab()}<tr>{this.rowresult()}</tr>{char.crlf()}</se:rowresult> </se:captionformat> <se:resultformat><table>{char.crlf()}{this.result()}</table></se:resultformat> </se:format> |
See Also
-
DataTable.Aggregate Viper Method
Aggregates the given datatable on the given column, grouped by the given columns. -
DataTable.Append Viper Method
Appends data from the given datatables to the source table, using the specified options. -
DataTable.Clone Viper Method
Return a clone of the given datatable. -
DataTable.Columns.Add Viper Method
Adds the a new column to the datatable. -
DataTable.Columns.Count Viper Method
Returns the number of columns in the datatable. -
DataTable.Columns.Exists Viper Method
Returns true if the column name exists, false otherwise. -
DataTable.Columns.GetName Viper Method
Gets the column name by its index. -
DataTable.Columns.GetNames Viper Method
Returns a datatable containing all the column names in this datatable. -
DataTable.Columns.GetOrdinal Viper Method
Returns the ordinal of the given column name. -
DataTable.Columns.GetType Viper Method
Returns the type of the given column. -
DataTable.Columns.Remove Viper Method
Removes an existing column from the datatable. -
DataTable.Columns.Rename Viper Method
Renames the column name. -
DataTable.Compute Viper Method
Computes a value based on a given expression after the datatable has been filtered by the given filter. The notation of the expression and filter parameter are described in the Microsoft documentation of the System.Data.DataColumn.Expression property. -
DataTable.Create Viper Method
Creates a new datatable containing a single row where the column names and the values are determined by the parameters. -
DataTable.CreateEmpty Viper Method
Create an empty datatable without columns and rows. -
DataTable.CreateForInputData Viper Method
Creates an empty datatable for use as input for the given macro parameter -
DataTable.Distinct Viper Method
Returns a datatable with a single column, containing all the distinct values in the column. -
DataTable.FindOne Viper Method
Finds a single row and returns the row number (-1 if not found). -
DataTable.GetBytes Viper Method
Gets the binary data (byte array) from a Binary Data-formatted DataTable. -
DataTable.GetValue Viper Method
Gets the value of a column in the first row of the given DataTable. -
DataTable.IsValid Viper Method
Determines whether the specified data table is valid (i.e. not closed and has at least one field). -
DataTable.Join Viper Method
Joins the datatables into one. -
DataTable.Rows.Add Viper Method
Adds a new row to the datatable with the given values. -
DataTable.Rows.Count Viper Method
Gets the number of rows in the datatable. -
DataTable.Rows.InsertAt Viper Method
Inserts a new row at given row index in the datatable. -
DataTable.Rows.Remove Viper Method
Removes the rows based on the given expression. -
DataTable.Rows.RemoveAll Viper Method
Removes all the rows in the datatable. -
DataTable.Rows.RemoveAt Viper Method
Removes the given row numbers from the datatable. -
DataTable.Rows.RemoveDuplicates Viper Method
Removes duplicate rows from the datatable. -
DataTable.Rows.RemoveRange Viper Method
Removes rows from the datatable, starting from the startIndex. -
DataTable.Search Viper Method
Searches the specified data table using the given expression. -
DataTable.SetValue Viper Method
Sets the value on the row and column of the given datatable. -
DataTable.SimpleFormat Viper Method
Formats the given datatable rows and returns a table. -
DataTable.SimpleFormatRow Viper Method
Formats a single row in the given datatable and returns a string using the given formatting parameters. -
DataTable.Sort Viper Method
Sorts the specified datatable. -
DataTable.ToXml Viper Method
Gets an XML representation of the DataTable. -
DataTable.Transpose Viper Method
Return the transposed version of the given datatable.
- Macro
- Macro Parameters
- Macro Parameter Properties
-
Vipers
-
Global Viper Methods
- AIM Viper Class
- Audit Viper Class
- Buffer Viper Class
- Cache Viper Class
- CacheFile Viper Class
- Calendar Viper Class
- Channel Viper Class
- Char Viper Class
- Cms Viper Class
- ContentType Viper Class
- Convert Viper Class
- Database Viper Class
-
- DataTable.Aggregate Viper Method
- DataTable.Append Viper Method
- DataTable.Clone Viper Method
- DataTable.Columns.Add Viper Method
- DataTable.Columns.Count Viper Method
- DataTable.Columns.Exists Viper Method
- DataTable.Columns.GetName Viper Method
- DataTable.Columns.GetNames Viper Method
- DataTable.Columns.GetOrdinal Viper Method
- DataTable.Columns.GetType Viper Method
- DataTable.Columns.Remove Viper Method
- DataTable.Columns.Rename Viper Method
- DataTable.Compute Viper Method
- DataTable.Create Viper Method
- DataTable.CreateEmpty Viper Method
- DataTable.CreateForInputData Viper Method
- DataTable.Distinct Viper Method
- DataTable.FindOne Viper Method
- DataTable.GetBytes Viper Method
- DataTable.GetValue Viper Method
- DataTable.IsValid Viper Method
- DataTable.Join Viper Method
- DataTable.Rows.Add Viper Method
- DataTable.Rows.Count Viper Method
- DataTable.Rows.InsertAt Viper Method
- DataTable.Rows.Remove Viper Method
- DataTable.Rows.RemoveAll Viper Method
- DataTable.Rows.RemoveAt Viper Method
- DataTable.Rows.RemoveDuplicates Viper Method
- DataTable.Rows.RemoveRange Viper Method
- DataTable.Search Viper Method
- DataTable.SetValue Viper Method
- DataTable.SimpleFormat Viper Method
- DataTable.SimpleFormatRow Viper Method
- DataTable.Sort Viper Method
- DataTable.ToXml Viper Method
- DataTable.Transpose Viper Method
- DateTime Viper Class
- Debug Viper Class
- DigiD Viper Class
- Env Viper Class
- FileSystem Viper Class
- FlexLayout Viper Class
- Html Viper Class
- Html.Color Viper Class
- Html.Css Viper Class
- Image Viper Class
- ImageProperties Viper Class
- ItemComments Viper Class
- ItemData Viper Class
- License Viper Class
- Locale Viper Class
- Logging Viper Class
- Login Viper Class
- Math Viper Class
- Payment Viper Class
- Personalization Viper Class
- PlaceHolder Viper Class
- Poll Viper Class
- Publication Viper Class
- RenderTemplate Viper Class
- Request Viper Class
- Response Viper Class
- Scf Viper Class
- Security Viper Class
- Session Viper Class
- Site Viper Class
- Smartlet Viper Class
- SmartletEditor Viper Class
- SmartletPreset Viper Class
- Smi Viper Class
- SmiData Viper Class
- Spice Viper Class
- Sql Viper Class
- StandardsCompliance Viper Class
- Storage Viper Class
- String Viper Class
- SXML Viper Class
- Sys Viper Class
- Tags Viper Class
- Translation Viper Class
- Url Viper Class
- User Viper Class
- UserItemFeedback Viper Class
- Xml Viper Class
- Local Viper Methods
-
Global Viper Methods
- SXML Data Types
- Examples
- Tips & Tricks