* Finish task #107374.

This commit is contained in:
songchenxuan
2023-11-27 21:24:19 +08:00
parent 4c7da14656
commit 1e438e6bc6
10 changed files with 119 additions and 16 deletions
+1
View File
@@ -2,6 +2,7 @@
$config->pivot = new stdclass();
$config->pivot->widthInput = 128;
$config->pivot->widthDate = 248;
$config->pivot->recPerPage = 50;
$config->pivot->fileType = array('xlsx' => 'xlsx', 'xls' => 'xls', 'html' => 'html', 'mht' => 'mht');
+2 -1
View File
@@ -289,6 +289,7 @@ class pivot extends control
$pivotID = $post->id;
$settings = $post->settings;
$filters = isset($_POST['searchFilters']) ? $_POST['searchFilters'] : (isset($_POST['filters']) ? $post->filters : array());
$page = isset($_POST['page']) ? $_POST['page'] : 0;
$filterType = 'result';
$pivot = $this->pivot->getById($pivotID);
@@ -314,7 +315,7 @@ class pivot extends control
list($data, $configs) = $this->pivot->genSheet($fields, $settings, $sql, $filterFormat, $langs);
}
$this->pivot->buildPivotTable($data, $configs, $fields, $sql);
$this->pivot->buildPivotTable($data, $configs, $page);
}
}
+4 -4
View File
@@ -4,10 +4,10 @@
.main-position {position: relative;}
.child-position {position: absolute; right: 0;}
.parent-position {padding-right: 160px;}
.datagrid {overflow: auto; max-height: 500px;}
@media (max-width: 1366px) {.datagrid {max-height: 500px;}}
@media (min-width: 1366px) and (max-width: 1919px) {.datagrid {max-height: 650px;}}
@media (min-width: 1920px) {.datagrid {max-height: 800px;}}
.reportData {overflow: auto; max-height: 500px;}
@media (max-width: 1366px) {.reportData {max-height: 500px;}}
@media (min-width: 1366px) and (max-width: 1919px) {.reportData {max-height: 650px;}}
@media (min-width: 1920px) {.reportData {max-height: 800px;}}
.reportData thead {position: sticky; background-color: #fff; top: -1px;}
.heading-padding, .datagrid-padding {padding-left: 6px; padding-right: 6px;}
+13 -2
View File
@@ -23,7 +23,6 @@ function expandTree()
function getQueryInfo()
{
// if not use JSON.parse(JSON.stringify()), edit pivotInfo also affects pivot. If click btn-query-origin, pivot setting also have summary field.
var pivotInfo = JSON.parse(JSON.stringify(pivot));
pivotInfo.searchFilters = JSON.parse(JSON.stringify(pivotInfo.filters));
pivotInfo.step = 4;
@@ -82,6 +81,7 @@ function initQueryBtn()
$('.btn-query').click(function()
{
var pivotInfo = getQueryInfo();
pivotInfo.page = 1;
refreshPivot(pivotInfo);
});
}
@@ -98,16 +98,27 @@ function initOriginQueryBtn()
{
var pivotInfo = getQueryInfo();
pivotInfo.settings['summary'] = 'notuse';
pivotInfo.page = 1;
refreshPivot(pivotInfo, true);
});
}
function queryPivotByPager(obj)
{
var pivotInfo = JSON.parse(JSON.stringify(pivot));
pivotInfo.page = $(obj).find('a').data('page');
var isOrigin = $('.btn-query-origin').hasClass('hidden');
if(isOrigin) pivotInfo.settings['summary'] = 'notuse';
refreshPivot(pivotInfo, isOrigin);
}
function refreshPivot(pivotInfo, isOrigin = false)
{
$.post(createLink('pivot', 'ajaxGetPivot'), pivotInfo,function(resp)
{
var myDatagrid = $('#datagirdInfo');
myDatagrid.find('.reportData').remove();
myDatagrid.empty();
myDatagrid.append(resp);
if(isOrigin)
+1
View File
@@ -76,6 +76,7 @@ $lang->pivot->showPivot = 'Show Pivot';
$lang->pivot->showOrigin = 'Show Origin Data';
$lang->pivot->showOriginItem = 'Show origin item';
$lang->pivot->recTotalTip = '<strong> %s </strong> items in total';
$lang->pivot->showOriginPlaceholder = new stdclass();
$lang->pivot->showOriginPlaceholder->slice = 'No need to configure';
+1
View File
@@ -76,6 +76,7 @@ $lang->pivot->showPivot = 'Show Pivot';
$lang->pivot->showOrigin = 'Show Origin Data';
$lang->pivot->showOriginItem = 'Show origin item';
$lang->pivot->recTotalTip = '<strong> %s </strong> items in total';
$lang->pivot->showOriginPlaceholder = new stdclass();
$lang->pivot->showOriginPlaceholder->slice = 'No need to configure';
+1
View File
@@ -76,6 +76,7 @@ $lang->pivot->showPivot = 'Show Pivot';
$lang->pivot->showOrigin = 'Show Origin Data';
$lang->pivot->showOriginItem = 'Show origin item';
$lang->pivot->recTotalTip = '<strong> %s </strong> items in total';
$lang->pivot->showOriginPlaceholder = new stdclass();
$lang->pivot->showOriginPlaceholder->slice = 'No need to configure';
+1
View File
@@ -76,6 +76,7 @@ $lang->pivot->showPivot = '查看透视表';
$lang->pivot->showOrigin = '查看原始数据';
$lang->pivot->showOriginItem = '展示原始条目';
$lang->pivot->recTotalTip = '共 <strong> %s </strong> 项';
$lang->pivot->showOriginPlaceholder = new stdclass();
$lang->pivot->showOriginPlaceholder->slice = '展示原始条目后无需配置切片';
+94 -8
View File
@@ -2197,22 +2197,72 @@ class pivotModel extends model
return true;
}
/**
* 通过合并单元格的数据对透视表进行分页
* Page pivot by configs merge cell data.
*
* @param array $configs
* @param int $page
* @param bool $useColumnTotal
* @static
* @access public
* @return bool
*/
public function pagePivot($configs, $page, $useColumnTotal)
{
// 当前在第几页
$nowPage = 1;
// 一共多少行
$pageCount = 0;
// 当前页目前多少行
$nowCount = 0;
// 记录当前第几个分组(项),共有多少行
$itemRow = array(0 => 0);
// 目标分页的起始行和结束行
$start = $end = -1;
foreach($configs as $key => $config)
{
if($nowPage == $page and $start == -1) $start = $pageCount;
if($nowPage == $page + 1 and $end == -1) $end = $pageCount;
$pageCount += $config[0];
$nowCount += $config[0];
$itemRow[] = $pageCount;
// 如果当前页超过了50行,换一页
if($nowCount >= $this->config->pivot->recPerPage)
{
$nowCount = 0;
if(isset($configs[$key + 1])) $nowPage += 1;
}
}
if($start == -1) $start = 0;
if($end == -1) $end = $pageCount;
// 获得当前页面有多少"项"
$endKey = array_search($end, $itemRow);
$startKey = array_search($start, $itemRow);
$itemCount = $endKey - $startKey;
// 如果是最后一页且使用了显示列的汇总,项数-1,
if($page == $nowPage and $useColumnTotal) $itemCount --;
return array($start, $end - 1, $itemCount, $nowPage);
}
/**
* Build table use data and rowspan.
*
* @param object $data
* @param array $configs
* @param array $fields
* @param int $page
* @access public
* @return void
*
*/
public function buildPivotTable($data, $configs, $fields = array(), $sql = '')
public function buildPivotTable($data, $configs, $page = 0)
{
$width = 128;
/* Init table. */
$table = "<table class='reportData table table-condensed table-striped table-bordered table-fixed datatable' style='width: auto; min-width: 100%' data-fixed-left-width='400'>";
$table = "<div class='reportData'><table class='table table-condensed table-striped table-bordered table-fixed datatable' style='width: auto; min-width: 100%' data-fixed-left-width='400'>";
$showOrigins = array();
$hasShowOrigin = false;
@@ -2225,7 +2275,6 @@ class pivotModel extends model
if($col->showOrigin) $hasShowOrigin = true;
}
/* Init table thead. */
$table .= "<thead>";
foreach($data->cols as $lineCols)
@@ -2250,10 +2299,17 @@ class pivotModel extends model
/* Init table tbody. */
$table .= "<tbody>";
$rowCount = 0;
$useColumnTotal = !empty($data->columnTotal) and $data->columnTotal === 'sum';
if($page) list($start, $end, $itemCount, $pageTotal) = $this->pagePivot($configs, $page, $useColumnTotal);
for($i = 0; $i < count($data->array); $i ++)
{
$rowCount ++;
if(!empty($data->columnTotal) and $data->columnTotal === 'sum' and $rowCount == count($data->array)) continue;
if($page and ($i < $start or $i > $end)) continue;
if($useColumnTotal and $rowCount == count($data->array)) continue;
$line = array_values($data->array[$i]);
$table .= "<tr class='text-center'>";
@@ -2282,8 +2338,8 @@ class pivotModel extends model
$table .= "</tr>";
}
/* Add column total. */
if(!empty($data->columnTotal) and $data->columnTotal === 'sum' and !empty($data->array))
/* Add column total. 如果分页了,只在最后一页展示 */
if($useColumnTotal and !empty($data->array) and (!$page or $page == $pageTotal))
{
$table .= "<tr class='text-center'>";
$table .= "<td colspan='" . count($data->groups) . "'>{$this->lang->pivot->step2->total}</td>";
@@ -2297,7 +2353,37 @@ class pivotModel extends model
}
$table .= "</tbody>";
$table .= "</table>";
$table .= "</table></div>";
if($page)
{
$recTotal = $end - $start + 1;
$itemCountTip = sprintf($this->lang->pivot->recTotalTip, $itemCount);
$leftPage = $page - 1;
$rightPage = $page + 1;
$leftPageClass = $page == 1 ? 'disabled' : '';
$rightPageClass = $page == $pageTotal ? 'disabled' : '';
if($recTotal) $table .= "<div class='table-footer'>
<ul class='pager'>
<li><div class='pager-label recTotal'>{$itemCountTip}</div></li>
<li class='pager-item-left first-page $leftPageClass' onclick='queryPivotByPager(this)'>
<a class='pager-item' data-page='1' href='javascript:;'><i class='icon icon-first-page'></i></a>
</li>
<li class='pager-item-left left-page $leftPageClass' onclick='queryPivotByPager(this)'>
<a class='pager-item' data-page='{$leftPage}' href='javascript:;'><i class='icon icon-angle-left'></i></a>
</li>
<li><div class='pager-label page-number'><strong>{$page}/{$pageTotal}</strong></div></li>
<li class='pager-item-right right-page $rightPageClass' onclick='queryPivotByPager(this)'>
<a class='pager-item' data-page='{$rightPage}' href='javascript:;'><i class='icon icon-angle-right'></i></a>
</li>
<li class='pager-item-right last-page $rightPageClass' onclick='queryPivotByPager(this)'>
<a class='pager-item' data-page='{$pageTotal}' href='javascript:;'><i class='icon icon-last-page'></i></a>
</li>
</ul>
</div>";
}
echo $table;
}
+1 -1
View File
@@ -62,7 +62,7 @@
<div id="filterMargin" class='hidden'></div>
<div id='datagirdInfo' class='datagrid'>
<?php $sql = $this->loadModel('chart')->parseSqlVars($pivot->sql, $pivot->filters);?>
<?php $this->pivot->buildPivotTable($data, $configs, json_decode(json_encode($pivot->fieldSettings), true), $sql);?>
<?php $this->pivot->buildPivotTable($data, $configs, 1);?>
</div>
</div>
<?php endif;?>