Class Grid - XML Generator for DHTMLX
$grid = new Grid( set encoding, default utf-8 )
$grid = new Grid;
or
$grid = new Grid('iso-8859-1');
pos
$grid->pos = 100;
total_count
$grid->total_count = 1000;
$grid->settings( array( 'key attribute' => 'value attribute' ) )
$grid->settings(
array(
"colwidth" => "px",
"splitat" => 2
)
);
$grid->column( array( 'key attribute' => 'value attribute' ) )
column simple
$grid->column(
array(
"type" => "edn",
"width" => "150",
"sort" => "str",
"format" => "0.00",
"label" => "Foo"
),
array(
"type" => "edn",
"width" => "150",
"sort" => "str",
"format" => "0.00",
"label" => "Bar"
),
array(
"type" => "edn",
"width" => "150",
"sort" => "str",
"format" => "0.00",
"label" => "Baz"
)
);
column with combo option
$grid->column(
array(
"type" => "co",
"width" => "150",
"sort" => "na",
"id" => "last",
"label" => "Combo",
"option" => array(
array("value" => "1", "text" => "One"),
array("value" => "2", "text" => "Two"),
array("value" => "3", "text" => "Three")
)
)
);
$grid->beforeInit('command', 'value 1', 'value 2', ...)
$grid->beforeInit("enableResizing", "false", "false");
$grid->afterInit('command', 'value 1', 'value 2', ...)
$grid->afterInit("enableResizing", "Label 2-1", "Label 2-2");
$grid->row( array( 'key attribute' => 'value attribute' ) )
$grid->row(
array(
"id" => 1,
"cell" => array("foo", "bar", "baz")
),
array(
"id" => 2,
"cell" => array("foo", "bar", array("class" => "css2", "text" => "baz"))
),
array(
"id" => 3,
"userdata" => array("name" => "some1", "value" => "Value 1"),
"cell" => array("foo", "bar", "baz")
),
array(
"id" => 4,
"userdata" => array("name" => "some2", "value" => "Value 2"),
"cell" => array("foo", "bar", "baz")
)
);
$grid->cell('id', 'value 1', 'value 2', ...)
$grid->cell(1, "foo", "bar", "baz");
$grid->cell(2, "foo", "bar", "baz");
$grid->cell(3, "foo", "bar", "baz");
$grid->cell(4, "foo", "bar", "baz");
$grid->userdata( array( 'key attribute' => 'value attribute' ) )
$grid->userdata(
array(
"name" => "some1",
"value" => "Value1"
),
array(
"name" => "some2",
"value" => "Value2"
)
);
$grid->header()
$grid->header();
return
header("Content-type: application/xml; charset=utf-8");
$grid->result()
echo $grid->result();
Print XML
Mode 1
<?php
include_once 'DHX.php';
$grid1 = new Grid;
$grid1->row(
array(
"id" => 1,
"cell" => array("foo 1", "bar 1", "baz 1")
),
array(
"id" => 2,
"cell" => array("foo 2", "bar 2", "baz 2")
),
array(
"id" => 3,
"cell" => array("foo 3", "bar 3", "baz 3")
),
array(
"id" => 4,
"cell" => array("foo 4", "bar 4", "baz 4")
),
array(
"id" => 5,
"cell" => array("foo 5", "bar 5", "baz 5")
)
);
$grid1->header();
echo $grid1->result();
?>
Result
<?xml version="1.0" encoding="utf-8"?>
<rows>
<row id="1">
<cell>foo 1</cell>
<cell>bar 1</cell>
<cell>baz 1</cell>
</row>
<row id="2">
<cell>foo 2</cell>
<cell>bar 2</cell>
<cell>baz 2</cell>
</row>
<row id="3">
<cell>foo 3</cell>
<cell>bar 3</cell>
<cell>baz 3</cell>
</row>
<row id="4">
<cell>foo 4</cell>
<cell>bar 4</cell>
<cell>baz 4</cell>
</row>
<row id="5">
<cell>foo 5</cell>
<cell>bar 5</cell>
<cell>baz 5</cell>
</row>
</rows>
Mode 2
<?php
include_once 'DHX.php';
$grid2 = new Grid("iso-8859-1");
$grid2->cell(1, "foo 1", "bar 1", "baz 1");
$grid2->cell(2, "foo 2", "bar 2", "baz 2");
$grid2->cell(3, "foo 3", "bar 3", "baz 3");
$grid2->cell(4, "foo 4", "bar 4", "baz 4");
$grid2->cell(5, "foo 5", "bar 5", "baz 5");
$grid2->header();
echo $grid2->result();
?>
Result
<?xml version="1.0" encoding="iso-8859-1"?>
<rows>
<row id="1">
<cell>foo 1</cell>
<cell>bar 1</cell>
<cell>baz 1</cell>
</row>
<row id="2">
<cell>foo 2</cell>
<cell>bar 2</cell>
<cell>baz 2</cell>
</row>
<row id="3">
<cell>foo 3</cell>
<cell>bar 3</cell>
<cell>baz 3</cell>
</row>
<row id="4">
<cell>foo 4</cell>
<cell>bar 4</cell>
<cell>baz 4</cell>
</row>
<row id="5">
<cell>foo 5</cell>
<cell>bar 5</cell>
<cell>baz 5</cell>
</row>
</rows>
<?php
include_once 'DHX.php';
$grid = new Grid;
// settings
$grid->settings(array("colwidth" => "px", "splitat" => 2));
// beforeInit
$grid->beforeInit("enableResizing", "false", "false");
// afterInit
$grid->afterInit("enableResizing", "Label 2-1", "Label 2-2");
// column
$grid->column(
array(
"type" => "ed",
"width" => "150",
"sort" => "str",
"label" => "Name"
),
array(
"type" => "ed",
"width" => "150",
"sort" => "str",
"label" => "E-mail"
),
array(
"type" => "ed",
"width" => "150",
"sort" => "str",
"label" => "Login"
)
);
// cell
$grid->cell(1, "Foo", "[email protected]", "foo");
$grid->cell(1, "Bar", "[email protected]", "bar");
$grid->cell(1, "Baz", "[email protected]", "baz");
$grid->header();
echo $grid->result();
?>
Result
<?xml version="1.0" encoding="utf-8"?>
<rows>
<head>
<settings>
<colwidth>px</colwidth>
<splitat>2</splitat>
</settings>
<beforeInit>
<call command="enableResizing">
<param>false,false</param>
</call>
</beforeInit>
<afterInit>
<call command="enableResizing">
<param>Label 2-1,Label 2-2</param>
</call>
</afterInit>
<column type="ed" width="150" sort="str">Name</column>
<column type="ed" width="150" sort="str">E-mail</column>
<column type="ed" width="150" sort="str">Login</column>
</head>
<row id="1">
<cell>Foo</cell>
<cell>[email protected]</cell>
<cell>foo</cell>
</row>
<row id="1">
<cell>Bar</cell>
<cell>[email protected]</cell>
<cell>bar</cell>
</row>
<row id="1">
<cell>Baz</cell>
<cell>[email protected]</cell>
<cell>baz</cell>
</row>
</rows>
Lucas Tiago de Moraes