Grid view

Presenting data in a table like layout is a common task in many web applications and websites. The GUI library comes with a simple grid component, that takes a multi dimention array of data, and turns it into a table (Grid view). Optionally each item (row) in the grid can be selectable.


/Grid.png


public function Render()
{
    // Prepare test data

    $data = array();
    $data["UniqueRowId1"] = array(
        "Filename"    => "ButtonBuy.png",
        "Size"           => "3.65 KB",
        "Modified"     => "2009-10-27 21:59:56"
    );
    $data["UniqueRowId2"] = array(
        "Filename"    => "LinkButton.png",
        "Size"           => "7 KB",
        "Modified"     => "2009-10-21 16:45:41"
    );
    $data["UniqueRowId3"] = array(
        "Filename"    => "TreeMenu.png",
        "Size"           => "10.08 KB",
        "Modified"     => "2009-10-21 16:45:52"
    );

    // Create post back button

    $button = new SMLinkButton("UniqueButtonId");
    $button->SetTitle("Click me to post back");

    // Create grid, assign data

    $grid = new SMGrid("UniqueId");
    $grid->SetData($data);
    $grid->EnableSelector("Filename");

    // Output grid, button, and selected value (if selection has been made)

    $output = $grid->Render() . "<br><br>" . $button->Render();

    if ($grid->GetSelectedId() !== null)
    {
        $output .= "<br><br> Selected ID: " . $grid->GetSelectedId();
        $output .= "<br> Selected Value: " . $grid->GetSelectedValue();
    }

    return $output;
}
The code snippet will generate a grid view identical to the image in the top of this page.


SMGrid class

Function Return type Description
__construct($id:string)
Create instance of grid with specified unique ID.
GetId()
String
Get unique ID with which the instance was created.
SetData($data:string[][])

Set data to be displayed in grid. Notice that each row must have a unique index, as shown here: $data["UniqueId"] = array("Column title 1" => "Value 1", "Column title 2" => "Value 2"). The indexes in the array containing the data, are used as column headers.
GetData()
String[][]
Get data set using SetData($data:string[][]).
SetSelectedId($id:string)

Set selected item using unique row index as described for the SetData($data:string[][]) function.
GetSelectedId()
String
Get ID for selected item. Returns NULL if no item is selected, or if post back has not been performed.
GetSelectedValue()
String
Get selected value, if selector has been enabled using EnableSelector($valueField:string).
EnableSelector()

Enable selector that makes items (rows) selectable. Use GetSelectedId() to get the unique index for the selected row.
EnableSelector($valueField:string)
Enable selector. Specify column containing value to post back, which will be available using the GetSelectedValue() function.
DisableSelector()

Disable selector. Items will now longer be selectable.
GetSelectorEnabled()
Boolean
Get value indicating whether selector is enabled or not.
SetRestoreSelection($value:boolean)

Set True to have selection restored after post back (default), False not to.
GetRestoreSelection()
Boolean
Get value indicating whether selection will be restored or not after post back.
SetAutoPostBack($value:boolean)

Set True to have control perform post back when a row is selected, False not to (default).
GetAutoPostBack()
Boolean
Get value indicating whether auto post back is enabled or not.
PerformedPostBack()
Boolean
Returns True if control performed a post back, False otherwise.
SetRender($value:boolean)

Set True to have control rendered when Render() function is invoked (default), False not to.
GetRender()
Boolean
Get value indicating whether control will be rendered or not, when invoking Render() function
Render() String Render and return client side control code.