JQueryeasyui is used in combination with ThinkPHP. regarding the problem of reading data display, the original project wrote an EasyUI class, which wrote a datagrig () method.
Public function _ datagrid ($ tag ){
$ Id =! Empty ($ tag ['id'])? $ Tag ['id']: strtolower (CONTROLLER_NAME. '_'. ACTION_NAME. '_ datagrid ');
$ Style =! Empty ($ tag ['style'])? $ Tag ['style']: '';
// Default parameter
$ DataOptions = array (
'Border' => false,
'Fit '=> true,
'Fitcolumns '=> true,
'Rownumbers '=> true,
'Singleselect' => true,
'Pagination' => true,
'Pagelist' => array (20, 30, 50, 80, 100 ),
'Pagesize' => cookie ('pagesize ')? Cookie ('pagesize'): C ('datagrid _ PAGE_SIZE '),
);
$ Options = $ tag ['options']? $ This-> autoBuildVar ($ tag ['options']): 'Array ()';
$ Fields = $ tag ['fields']? $ This-> autoBuildVar ($ tag ['fields']): 'null ';
$ ParseStr ='
\ 'Style = "'. $ style.'">
';$ ParseStr. =' $ Arr): if (isset ($ arr [\ 'formatter \ ']): unset ($ arr [\ 'formatter \']); endif; echo"
| ". $ Key ." | "; Endforeach; endif;?> ';$ ParseStr. ='
';
Return $ parseStr;
}
This is the logic written in the controller.
$ Datagrid = array (
'Options' => array (
'Title' => $ currentpos,
'URL' => U ('UC/page', array ('grid' => 'datagrid ')),
'Toolbar' => 'UC _ pages_datagrid_toolbar ',
),
'Fields' => array (
'Page' => array ('field' => 'Page', 'width' => 15, 'sortable' => true ),
'Access' => array ('field' => 'private', 'width' => 15, 'sortable' => true ),
'Management operation' => array ('field' => 'id', 'width' => 15, 'formatter '=> 'ucagesoperateformatter '),
)
);
$ This-> assign ('datagrid ', $ datagrid );
The page references tags in this way, and the data comes out.
The problem is that this is the pages table for operations. the values of Field id, page, private, and private are 0 or 1, in the controller, field =, 'private' is used to display 0 or 1 to the page, but our requirement is that when the value of the database privat field is 0, the page shows public and 1, private is displayed on the page. What can be done without changing the table content and structure, that is, not moving the table? Please help me. thank you!
Reply to discussion (solution)
My mind was so hot that I suddenly found that the display of the column with management operations could be realized!
On the pages page, I defined a formatting function ucPagesAccessFormatter ()
// Access format
Function ucPagesAccessFormatter (val ){
Var btn = [];
If (val = 0 ){
Return "public ";
} Else {
Return "private ";
}
}
Write in the controller:
'Fields' => array (
'Page' => array ('field' => 'Page', 'width' => 15, 'sortable' => true ),
'Access' => array ('field' => 'private', 'width' => 15, 'formatter '=> 'ucagesaccessformatter '),
'Management operation' => array ('field' => 'id', 'width' => 15, 'formatter '=> 'ucagesoperateformatter '),
)
The result page is displayed:
Who did you reply? I'll give you a score. I can't give it to myself, or it will be a waste!
Er, easyUI, php