📄 ajaxgrid.php
字号:
function customFilter($colNumber, $filterString){
$colValues = array_values($this->_columns);
$column = $colValues[$colNumber-1];
$column->setFilterActive(true);
$column->setCustomFilter(true);
$column->setFilterString($filterString);
$this->actualizeFiltersWithDependencies($colNumber);
$this->actualizeData();
}
/**
* Quita el filtro de una columna especifica.
*
* @param Integer $rowNumber
*/
function removeFilter($colNumber){
$colValues = array_values($this->_columns);
$column = $colValues[$colNumber-1];
$column->setFilterActive(false);
$column->setCustomFilter(false);
$this->actualizeFiltersWithDependencies($colNumber);
$this->actualizeData();
}
/**
* Obtiene informaci贸n sobre las columnas mostradas.
*
* @return string
*/
function getRowsInfo(){
$ret = '';
$firstRow = $this->_actualRow + 1;
$lastRow = min($firstRow + $this->_maxRows - 1, $this->_totalRows);
$totalRows = $this->_totalRows;
if($totalRows > 0){
$ret = str_replace(
array('{$firstRow}','{$lastRow}','{$totalRows}'),
array($firstRow,$lastRow,$totalRows),
$this->_tp_rowsInfo);
}
else{
$ret = $this->_tp_rowsInfo_empty;
}
return $ret;
}
/**
* Obtiene el html de la secci贸n para cambiar la cantidad de filas por p谩gina.
*
* @return string
*/
function getChangeRowsPerPage(){
return str_replace(
array('{$id}','{$value}','{$action}'),
array($this->_gridName.'_id_txt_change_rows_per_page',$this->_maxRows,$this->getChangeRowPerPageAction()),
$this->_tp_rowsPerPage);
}
/**
* Obtiene los t铆tulos de la tabla entre <thead> y </thead>
*
* @return string
*/
function getTableHeader(){
$ret =
'<tr>';
$colNum = 1;
$totalPercent = 100;
$colCount = count($this->_columns);
foreach($this->_columns as $key => $value){
$width = $value->getWidth();
if(strstr($width,'%')){
$totalPercent -= intval($width);
}
elseif($width == NULL){
$width = strval((int)($totalPercent / $colCount)).'%';
$totalPercent -= (int)($totalPercent / $colCount);
}
$colCount--;
$filterButton = '';
if($value->isFilteredColumn()){
if($value->isFilterActive()){
$src = $this->_filtered_button;
}
else{
$src = $this->_filter_button;
}
$filterButton = "<img onclick=\"showFilterMenu(this,'{$this->_gridName}_filter_menu_{$colNum}');\" alt=\"filter\" src=\"{$src}\" style=\"cursor:pointer;\"/>";
}
if($value->isSortable()){
$css = $this->_css_sortable;
if($this->_actualSortedColumn == $colNum - 1){
$css .= " {$this->_css_sorted}";
$css .= $this->_actualSortDir == AjaxGrid::$ASC ? " {$this->_css_sorted_asc}" : " {$this->_css_sorted_desc}";
}
if($filterButton == ''){
$ret .=
"<th class=\"{$css}\" width=\"{$width}\">
<a onclick=\"{$this->getSort($colNum)}\">{$key}</a>
</th>";
}
else{
$ret .=
"<th class=\"{$css}\" width=\"{$width}\">
<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
<tr><td align=\"left\" width=\"1%\">
{$filterButton}
</td>
<td width=\"99%\">
<a onclick=\"{$this->getSort($colNum)}\">{$key}</a>
</td></tr>
</table>
{$this->getFilterMenu($value,$colNum)}
</th>";
}
}
else{
if($filterButton == ''){
$ret .=
"<th width=\"{$width}\">
{$key}
</th>";
}
else{
$ret .=
"<th class=\"{$css}\" width=\"{$width}\">
<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
<tr><td align=\"left\" width=\"1%\">
{$filterButton}
</td>
<td width=\"99%\">
{$key}
</td></tr>
</table>
{$this->getFilterMenu($value,$colCount)}
</th>";
}
}
$colNum++;
}
$ret .=
'</tr>';
return $ret;
}
/**
* Obtiene el contenido de la tabla entre <tbody> y </tbody>
*
* @return string
*/
function getTableContent(){
$ret = '';
$i = 0;
$totalColums = count($this->_columns);
foreach($this->_data as $dataValue){
$css = $i % 2 == 0 ? $this->_css_odd : $this->_css_even;
$ret .= "<tr class=\"{$css}\">";
$colNum = 1;
$totalPercent = 100;
$colCount = $totalColums;
foreach($this->_columns as $columnValue){
$width = $columnValue->getWidth();
if(strstr($width,'%')){
$totalPercent -= intval($width);
}
elseif($width == NULL){
$width = strval((int)($totalPercent / $colCount)).'%';
$totalPercent -= (int)($totalPercent / $colCount);
}
$colCount--;
if($columnValue instanceof ColumnMapped){
$valueToShow = vsprintf($columnValue->getFormat(),$this->getFieldsMapped($columnValue->getFields(),$dataValue));
$valueToShow = $valueToShow == NULL ? $this->_nullValue : $valueToShow;
}
elseif($columnValue instanceof ColumnComboMapped){
$valueToShow = $columnValue->getHtml($dataValue);
}
$ret .= "<td width=\"{$width}\"> {$valueToShow} </td>";
}
$ret .= '</tr>';
$i++;
}
return $ret;
}
/**
* IE 6 no soporta innerHtml para table, tr, tbody, etc... asi que bue...
* Retorna la tabla con tbody y thead.
*
* @return string
*/
function getTable(){
return $this->fl().
"<table width=\"100%\" class=\"{$this->_css_table}\" border=\"{$this->_border}\" cellpadding=\"{$this->_cellpadding}\" cellspacing=\"{$this->_cellspacing}\">
<thead>
{$this->getTableHeader()}
</thead>
<tbody>
{$this->getTableContent()}
</tbody>
</table>";
}
/**
* Retorna un string con la representaci贸n html de la grilla completa.
*
* @return string
*/
function getHtml(){
$this->actualizeData();
$navigationBar1 = $this->getNavigationBar1();
$navigationBar2 = $this->getNavigationBar2();
$data =
"<div id=\"{$this->_gridName}_complete_table_id\">
{$this->getTable()}
</div>";
$rowsInfo = $this->addId($this->getRowsInfo(),'rows_info');
$rowsPerPage = $this->addId($this->getChangeRowsPerPage(),'change_rows_per_page');
return $this->getLoading() . str_replace(
array('{$navigarionBar1}', '{$data}', '{$navigarionBar2}', '{$rowsInfo}', '{$rowsPerPage}'),
array($navigationBar1, $data, $navigationBar2, $rowsInfo,$rowsPerPage),
$this->_tp_grid);
}
/**
* Actualiza el valor para mostrar cuando hay valores nulos o strings vac铆os.
*
* @param string $val nueva cantidad
*/
function setNullValue($val){
$this->_nullValue = $val;
}
/**
* Obtiene el valor para mostrar cuando hay valores nulos o strings vac铆os.
*
* @return string
*/
function getNullValue(){
return $this->_nullValue;
}
/**
* Actualiza la condici贸n where.
*
* @param string $val nueva condicion
*/
function setWhereCondition($val){
$this->_whereCondition = $val;
}
/**
* Obtiene la condici贸n where.
*
* @return string
*/
function getWhereCondition(){
return $this->_whereCondition;
}
/**
* Actualiza el ancho en pixels del menu de filtrado.
*
* @param string $val nuevo ancho
*/
function setFilterMenuWidth($val){
$this->_filterMenuWidth = $val;
}
/**
* Obtiene el ancho en pixels del menu de filtrado.
*
* @return string
*/
function FilterMenuWidth(){
return $this->_filterMenuWidth;
}
/**
* Actualiza el alto en pixels del menu de filtrado.
*
* @param string $val nuevo alto
*/
function setFilterMenuHeight($val){
$this->_filterMenuHeight = $val;
}
/**
* Obtiene el alto en pixels del menu de filtrado.
*
* @return string
*/
function FilterMenuHeight(){
return $this->_filterMenuHeight;
}
/**
* Actualiza cellpadding para la tabla.
*
* @param Integer $val nueva cantidad
*/
function setCellPadding($val){
$this->_cellpadding = $val;
}
/**
* Obtiene cellpadding para la tabla.
*
* @return Integer
*/
function getCellPadding(){
return $this->_cellpadding;
}
/**
* Actualiza cellspacing para la tabla.
*
* @param Integer $val nueva cantidad
*/
function setCellSpacing($val){
$this->_cellspacing = $val;
}
/**
* Obtiene cellspacing para la tabla.
*
* @return Integer
*/
function getCellSpacing(){
return $this->_cellspacing;
}
/**
* Actualiza border para la tabla.
*
* @param Integer $val nueva cantidad
*/
function setBorder($val){
$this->_border = $val;
}
/**
* Obtiene border para la tabla.
*
* @return Integer
*/
function getBorder(){
return $this->_border;
}
/**
* Actualiza la cantidad m谩xima de filas para esta tabla.
*
* @param Integer $maxRows nueva cantidad
*/
function setMaxRows($maxRows){
$this->_maxRows = $maxRows > 0 ? $maxRows : 1;
$this->_actualRow = 0;
$this->actualizeData();
}
/**
* Obtiene la cantidad m谩xima de filas para esta tabla.
*
* @return Integer
*/
function getMaxRows(){
return $this->_maxRows;
}
/**
* Actualiza la cantidad m谩xima de links por p谩gina.
*
* @param Integer $maxPageLinks nueva cantidad
*/
function setMaxPageLinks($maxPageLinks){
$this->_maxPageLinks = $maxPageLinks;
}
/**
* Obtiene la cantidad m谩xima de filas para esta tabla.
*
* @return Integer
*/
function getMaxPageLinks(){
return $this->_maxPageLinks;
}
/**
* Actualiza el campo por el que se est谩 ordenando actualmente.
*
* @param string $sortBy nuevo valor
*/
function setActualSortBy($sortBy){
$this->_actualSortBy = $sortBy;
}
/**
* Obtiene el campo por el que se est谩 ordenando actualmente.
*
* @return string
*/
function getActualSortBy(){
return $this->_actualSortBy;
}
/**
* Actualiza la direcci贸n por la que se est谩 ordenando actualmente.
*
* @param string $sortDir nuevo valor
*/
function setActualSortDir($sortDir){
$this->_actualSortDir = $sortDir;
}
/**
* Obtiene la direcci贸n por la que se est谩 ordenando actualmente.
*
* @return string
*/
function getActualSortDir(){
return $this->_actualSortDir;
}
/**
* Actualiza la columna actualmente ordenada, comienza en 0.
*
* @param string $colNumber nuevo valor
*/
function setActualSortedCol($colNumber){
$this->_actualSortedColumn = $colNumber;
}
/**
* Obtiene a columna actualmente ordenada, comienza en 0.
*
* @return string
*/
function getActualSortedCol(){
return $this->_actualSortedColumn;
}
/**
* Obtiene el html para el boton previous.
*
* @return string
*/
function getPreviousButton(){
$action = $this->getGoToRow($this->_actualRow - $this->_maxRows);
if(($this->_totalRows > 0) && ($this->_actualRow > 0)){
return str_replace('{$action}',$action,$this->_tp_previous);
}
else{
return $this->_tp_no_previous;
}
}
/**
* Obtiene el html para el boton siguiente.
*
* @return string
*/
function getNextButton(){
$action = $this->getGoToRow($this->_actualRow + $this->_maxRows);
if(($this->_totalRows > 0) && ($this->_actualRow < ($this->_totalRows - $this->_maxRows))){
return str_replace('{$action}',$action,$this->_tp_next);
}
else{
return $this->_tp_no_next;
}
}
/**
* Obtiene el html para el boton primera p谩gina.
*
* @return string
*/
function getFirstButton(){
$action = $this->getGoToRow(0);
if(($this->_totalRows > 0) && ($this->_actualRow > 0)){
return str_replace('{$action}',$action,$this->_tp_first);
}
else{
return $this->_tp_no_first;
}
}
/**
* Obtiene el html para el boton 煤ltima p谩gina.
*
* @return string
*/
function getLastButton(){
$div = (int)($this->_totalRows / $this->_maxRows);
$rest = (int)($this->_totalRows % $this->_maxRows);
$lastRow = $div * $this->_maxRows - ($rest ? 0 : $this->_maxRows);
$action = $this->getGoToRow($lastRow);
if(($this->_totalRows > 0) && ($this->_actualRow < $lastRow)){
return str_replace('{$action}',$action,$this->_tp_last);
}
else{
return $this->_tp_no_last;
}
}
/**
* Obtiene el html para la lista de links p谩ginas.
*
* @return string
*/
function getPageLinks(){
$actualRow = $this->_totalRows <= $this->_maxRows ? '':
str_replace('{$pageNumber}',(int)($this->_actualRow/$this->_maxRows)+1,$this->_tp_actual_page_link);
return $this->getPageLinksBefore().$actualRow.$this->getPageLinksAfter();
}
// Parametros de configuracion
/**
* Actualiza el template para el bot贸n anterior.
*
* @param string $tmp nuevo valor
*/
function setTemplatePrevious($tmp){
$this->_tp_previous = $tmp;
}
/**
* Obtiene el template para el bot贸n anterior.
*
* @return string
*/
function getTemplatePrevious(){
return $this->_tp_previous;
}
/**
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -