DataTable Distinct Example

Example of how the datatable.distinct viper method searches for all distinct values in a datatable column.

Smartsite SXML CopyCode image Copy Code
<se:xmldatatable save="cars" resulttype="datatable">
    <se:row>
        <se:col name="brand">Audi</se:col>
        <se:col name="model">A3</se:col>
    </se:row>
    <se:row>
        <se:col>Audi</se:col>
        <se:col>A4</se:col>
    </se:row>
    <se:row>
        <se:col>Alfa Romeo</se:col>
        <se:col>Giulietta</se:col>
    </se:row>
    <se:row>
        <se:col>Volkswagen</se:col>
        <se:col>Polo</se:col>
    </se:row>
    <se:row>
        <se:col>Seat</se:col>
        <se:col>Leon</se:col>
    </se:row>
    <se:row>
        <se:col>Volkswagen</se:col>
        <se:col>Golf</se:col>
    </se:row>
    <se:row>
        <se:col>Audi</se:col>
        <se:col>A7</se:col>
    </se:row>
</se:xmldatatable>

{debug.write(datatable.distinct($cars, brand))}
Example Result CopyCode image Copy Code
brand=Audi
brand=Alfa Romeo
brand=Volkswagen
brand=Seat
SXML