初步测试显示表格成功
This commit is contained in:
parent
e9d2d19a71
commit
0cd676d726
@ -12,6 +12,7 @@
|
||||
require_once 'form/form_button.php';
|
||||
require_once 'form/form.php';
|
||||
|
||||
require_once "ui_tab.php";
|
||||
require_once 'ui_sidebar.php';
|
||||
// require_once "ui_tab.php";
|
||||
// require_once 'ui_sidebar.php';
|
||||
require_once "ui_navbar.php";
|
||||
require_once 'ui_table.php';
|
||||
|
260
ui_table.php
260
ui_table.php
@ -4,193 +4,137 @@
|
||||
|
||||
class UITable
|
||||
{
|
||||
private $title="";
|
||||
protected $columns=null;
|
||||
protected $columns_label=array(); //即使用label来显示列头
|
||||
private $heading=null;
|
||||
private $heading_style="default";
|
||||
private $body=null;
|
||||
private $fields=null;
|
||||
|
||||
private $row_out=0;
|
||||
private $col_out=0;
|
||||
|
||||
public function __construct1($name)
|
||||
public function set_heading($h)
|
||||
{
|
||||
$this->title=$name;
|
||||
$this->heading=$h;
|
||||
}
|
||||
|
||||
public function __construct2($name,$field_list)
|
||||
public function set_heading_style($hs)
|
||||
{
|
||||
$this->title=$name;
|
||||
$this->columns=$field_list;
|
||||
$this->heading_style=$hs;
|
||||
}
|
||||
|
||||
public function set_cols($name)
|
||||
public function set_body_text($bt)
|
||||
{
|
||||
$this->columns=$name;
|
||||
$this->body=$bt;
|
||||
}
|
||||
|
||||
public function add_col($name,$label=null)
|
||||
public function set_fields($f)
|
||||
{
|
||||
if($this->columns==null)
|
||||
$this->columns=array();
|
||||
|
||||
if(is_array($name))
|
||||
{
|
||||
for($i=0;$i<count($name);$i++)
|
||||
$this->columns[]=$name[$i];
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->columns[]=$name; //增加$name到columns数组中去,不需要返回值的情况下比array_push快(PHP.net官网说的)
|
||||
|
||||
if($label!=null)
|
||||
$this->columns_label[$name]=$label;
|
||||
}
|
||||
}
|
||||
|
||||
public function set_col_label($name,$label)
|
||||
{
|
||||
if($name!=null&&$label!=null)
|
||||
$this->columns_label[$name]=$label;
|
||||
}
|
||||
|
||||
public function echo()
|
||||
{
|
||||
echo '<div id="'.$this->title.'"></div>';
|
||||
}
|
||||
|
||||
private function echo_col($index)
|
||||
{
|
||||
$name=$this->columns[$index];
|
||||
|
||||
if(array_key_exists($name,$this->columns_label))
|
||||
echo '{ key: "'.$name.'", label: "'.$this->columns_label[$name].'"}';
|
||||
else
|
||||
echo $name;
|
||||
$this->fields=$f;
|
||||
}
|
||||
|
||||
public function start()
|
||||
{
|
||||
echo "<script>
|
||||
YUI().use(
|
||||
'aui-datatable',
|
||||
function(Y)
|
||||
{
|
||||
var columns = [";
|
||||
echo '<div class="panel panel-'.$this->heading_style.'">';
|
||||
|
||||
echo "'";$this->echo_col(0);echo "'";
|
||||
if($this->heading!=null)
|
||||
echo '<div class="panel-heading">'.$this->heading.'</div>';
|
||||
|
||||
for($i=1;$i<count($this->columns);$i++)
|
||||
if($this->body!=null)
|
||||
echo '<div class="panel-body"><p>'.$this->body.'</p></div>';
|
||||
|
||||
echo '<table class="table">';
|
||||
|
||||
if($this->fields!=null)
|
||||
{
|
||||
echo ",'";$this->echo_col($i);echo "'";
|
||||
echo '<tr>';
|
||||
foreach($this->fields as $field)
|
||||
echo '<th>'.$field.'</th>';
|
||||
echo '</tr>';
|
||||
}
|
||||
|
||||
echo "];
|
||||
|
||||
var data=[";
|
||||
}
|
||||
|
||||
public function start_row()
|
||||
public function start_row (){echo '<tr>';}
|
||||
public function end_row (){echo '</tr>';}
|
||||
|
||||
public function start_col (){echo '<td>';}
|
||||
public function end_col (){echo '</td>';}
|
||||
|
||||
public function echo_col ($text){echo '<td>'.$text.'</td>';}
|
||||
|
||||
public function echo_row ($text_list)
|
||||
{
|
||||
if($this->row_out!=0)
|
||||
echo ',
|
||||
{';
|
||||
else
|
||||
echo '{';
|
||||
start_row();
|
||||
|
||||
$this->col_out=0;
|
||||
}
|
||||
foreach($text_list as $text)
|
||||
echo_col($text);
|
||||
|
||||
public function out_col($contact)
|
||||
{
|
||||
echo $this->columns[$this->col_out]." : '".$contact."'";
|
||||
|
||||
++$this->col_out;
|
||||
|
||||
if($this->col_out<count($this->columns))
|
||||
echo ',';
|
||||
else
|
||||
{
|
||||
echo '}';
|
||||
++$this->row_out;
|
||||
}
|
||||
end_row();
|
||||
}
|
||||
|
||||
public function end()
|
||||
{
|
||||
echo "];
|
||||
|
||||
new Y.DataTable.Base(
|
||||
{
|
||||
columnset: columns,
|
||||
recordset: data
|
||||
}
|
||||
).render('#".$this->title."');
|
||||
}
|
||||
);
|
||||
|
||||
</script>";
|
||||
echo '</table>
|
||||
</div>';
|
||||
}
|
||||
};//class UITable
|
||||
|
||||
class UISQLTable extends UITable
|
||||
{
|
||||
private $sql_result=null;
|
||||
private $bool_text=array();
|
||||
|
||||
public function __construct($label,$sql_table_name,$field_list,$where)
|
||||
{
|
||||
parent::__construct2($label,$field_list);
|
||||
|
||||
if($field_list==null)
|
||||
{
|
||||
$field_list=get_field_list($sql_table_name);
|
||||
|
||||
$this->set_cols($field_list);
|
||||
|
||||
$this->sql_result=select_table($sql_table_name,null,$where,0,0);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->set_cols($field_list);
|
||||
|
||||
$this->sql_result=select_table($sql_table_name,$field_list,$where,0,0);
|
||||
}
|
||||
}
|
||||
|
||||
public function SetBoolText($field,$true_text,$false_text)
|
||||
{
|
||||
$this->bool_text[$field]=array($false_text,$true_text);
|
||||
}
|
||||
|
||||
public function get_sql_result()
|
||||
{
|
||||
return $this->sql_result;
|
||||
}
|
||||
|
||||
public function echo()
|
||||
{
|
||||
parent::echo();
|
||||
|
||||
$this->start();
|
||||
|
||||
for($r=0;$r<count($this->sql_result);$r++)
|
||||
{
|
||||
$row=$this->sql_result[$r];
|
||||
|
||||
$this->start_row();
|
||||
for($c=0;$c<count($row);$c++)
|
||||
{
|
||||
if(array_key_exists($this->columns[$c],$this->bool_text))
|
||||
{
|
||||
$this->out_col($this->bool_text[$this->columns[$c]][$row[$c]]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->out_col($row[$c]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->end();
|
||||
}
|
||||
};//class UISQLTable
|
||||
// class UISQLTable extends UITable
|
||||
// {
|
||||
// private $sql_result=null;
|
||||
// private $bool_text=array();
|
||||
//
|
||||
// public function __construct($label,$sql_table_name,$field_list,$where)
|
||||
// {
|
||||
// parent::__construct2($label,$field_list);
|
||||
//
|
||||
// if($field_list==null)
|
||||
// {
|
||||
// $field_list=get_field_list($sql_table_name);
|
||||
//
|
||||
// $this->set_cols($field_list);
|
||||
//
|
||||
// $this->sql_result=select_table($sql_table_name,null,$where,0,0);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// $this->set_cols($field_list);
|
||||
//
|
||||
// $this->sql_result=select_table($sql_table_name,$field_list,$where,0,0);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public function SetBoolText($field,$true_text,$false_text)
|
||||
// {
|
||||
// $this->bool_text[$field]=array($false_text,$true_text);
|
||||
// }
|
||||
//
|
||||
// public function get_sql_result()
|
||||
// {
|
||||
// return $this->sql_result;
|
||||
// }
|
||||
//
|
||||
// public function echo()
|
||||
// {
|
||||
// parent::echo();
|
||||
//
|
||||
// $this->start();
|
||||
//
|
||||
// for($r=0;$r<count($this->sql_result);$r++)
|
||||
// {
|
||||
// $row=$this->sql_result[$r];
|
||||
//
|
||||
// $this->start_row();
|
||||
// for($c=0;$c<count($row);$c++)
|
||||
// {
|
||||
// if(array_key_exists($this->columns[$c],$this->bool_text))
|
||||
// {
|
||||
// $this->out_col($this->bool_text[$this->columns[$c]][$row[$c]]);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// $this->out_col($row[$c]);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// $this->end();
|
||||
// }
|
||||
// };//class UISQLTable
|
||||
?>
|
||||
|
Loading…
x
Reference in New Issue
Block a user