* pivot: reload custom pivot table when query conditions changed.

This commit is contained in:
liugang
2023-11-02 09:25:56 +08:00
parent a2ed5053c4
commit 1d563a84b7
3 changed files with 54 additions and 3 deletions
+41
View File
@@ -76,6 +76,47 @@ function loadWorkload()
loadPage(link, '#table-pivot-preview');
}
/**
* 查询条件改变时重新加载自定义透视表。
* Reload custom pivot table when query conditions changed.
*
* @access public
* @return void
*/
function loadCustomPivot()
{
let filterValues = [];
$('#conditions .filter').each(function()
{
const $filter = $(this);
if ($filter.hasClass('filter-input'))
{
filterValues.push($filter.find('input').val());
}
else if($filter.hasClass('filter-select'))
{
filterValues.push($filter.find('.pick-value').val().filter(Boolean));
}
else if($filter.hasClass('filter-date') || $filter.hasClass('filter-datetime'))
{
const $pickValue = $filter.find('.pick-value');
if($pickValue.length == 1)
{
filterValues.push($pickValue.val());
}
else if($pickValue.length == 2)
{
filterValues.push({begin: $pickValue.eq(0).val(), end: $pickValue.eq(1).val()});
}
}
});
const data = {'filterValues': JSON.stringify(filterValues)};
const params = window.btoa('dimensionID=' + dimension + '&groupID=' + groupID + '&pivotID=' + pivotID);
const link = $.createLink('pivot', 'preview', 'dimension=' + dimension + '&group=' + groupID + '&module=pivot&method=show&params=' + params);
postAndLoadPage(link, data, '#table-pivot-preview');
}
/**
* 把日期字符串转换成日期对象。
* Convert date string to date object.
+2
View File
@@ -10,6 +10,8 @@ declare(strict_types = 1);
*/
namespace zin;
jsVar('pivotID', $pivot->id);
$filters = array();
$options = array();
foreach($pivot->filters as $filter)
+11 -3
View File
@@ -332,12 +332,20 @@ class pivotZen extends pivot
list($pivotTree, $pivot, $groupID) = $this->pivot->getPreviewPivots($dimensionID, $groupID, $pivotID);
if($pivot)
{
if($this->post->filterValues)
{
$filterValues = json_decode($this->post->filterValues, true);
foreach($filterValues as $key => $value) $pivot->filters[$key]['default'] = $value;
}
list($sql, $filterFormat) = $this->pivot->getFilterFormat($pivot->sql, $pivot->filters);
$processSqlData = $this->loadModel('chart')->getTables($sql);
$sql = $processSqlData['sql'];
$tables = $this->loadModel('chart')->getTables($sql);
$sql = $tables['sql'];
$fields = json_decode(json_encode($pivot->fieldSettings), true);
$langs = json_decode($pivot->langs, true);
list($data, $configs) = $this->pivot->genSheet(json_decode(json_encode($pivot->fieldSettings), true), $pivot->settings, $sql, $filterFormat, json_decode($pivot->langs, true));
list($data, $configs) = $this->pivot->genSheet($fields, $pivot->settings, $sql, $filterFormat, $langs);
$this->view->data = $data;
$this->view->configs = $configs;
}