【问题标题】:Jump to a specific page in a QDataGrid跳转到 QDataGrid 中的特定页面
【发布时间】:2015-03-13 01:45:21
【问题描述】:

请注意,这个问题专门针对 QCubed PHP 框架的 QDataGrid 功能。 API documentation for QDataGrid 没有描述任何回答这个问题的功能。 QCubed samples site 也没有解决方案。

问题:

有时 QDataGrid 有一百多个页面。有没有办法跳转到多页数据网格中的特定页面?

例如,有一个 167 页的 QDataGrid。 QPaginator 只显示:

上一页 | 1 2 3 4 5 6 7 8 ... 167 |下一个

所以如果用户想要去到第 100 页,他必须进行大量的点击。 (我知道 QDataGrid 可以过滤和排序,但有时这些帮助不大)。

我正在考虑添加一个“跳转到页面”QTextbox,但我如何告诉 QDataGrid 到文本框中指定的页面?

【问题讨论】:

  • 您通过研究尝试或发现了什么?要缩小您的问题范围,请编辑您的努力所在以及您遇到的具体问题。
  • @whoever 搁置了这个问题——考虑到框架,这不是一个简单的问题,也不是太宽泛(似乎提问者已经编辑了它)。如果可能,请取消保留。
  • 添加了更多细节,包括所做的研究工作。请取消。
  • 添加了更多细节,包括所做的研究工作。请取消保留:@J0e3gan。谢谢。
  • 添加了更多细节,包括所做的研究工作。请取消:@andy。提前致谢。

标签: datagrid pagination qcubed


【解决方案1】:

你可以在你的代码中使用这个分页来获得它

    $this->auctionData = new QDataGrid($this);
    $this->auctionData->CssClass = 'table table-striped';
    $this->auctionData->UseAjax = true;
    $this->auctionData->Paginator = new QPaginator($this->auctionData);
    $this->auctionData->ItemsPerPage = 5;
    $this->auctionData->SetDataBinder('BindDataGrid_ExistingAuctions', $this);

在 SetDataBinder 中调用函数。

public function BindDataGrid_ExistingAuctions(){
  $intCfglaneandrun = array();
  $intCfglaneandrun = // your array goes here;

        $this->auctionData->TotalItemCount = count($intCfglaneandrun);
        $this->auctionData->DataSource = $intCfglaneandrun;

}

TotalItemCount 获取在分页和迭代中使用的计数,并且数据源将具有可以在数据网格中显示的数据。

【讨论】:

    【解决方案2】:

    我终于找到了一种使用 qcubed 的方法,也许它可以帮助将来的人。基本上,我只是在 Form_Create() 函数中添加了一个 QIntegerTextBox 和一个 QButton,并且我添加了一个动作来为 QDataGrid 的 Paginator->PageNumber 属性设置一个值。像这样:

    protected function Form_Create() {
            parent::Form_Create();
    
            // Instantiate the Meta DataGrid
            $this->dtgSignatories = new SignatoryDataGrid($this);
    
            // Style the DataGrid (if desired)
    
            // Add Pagination (if desired)
            $this->dtgSignatories->Paginator = new QPaginator($this->dtgSignatories);
            $this->dtgSignatories->ItemsPerPage = __FORM_DRAFTS_FORM_LIST_ITEMS_PER_PAGE__;
    
    // more code here
    // to add columns to the datagrid
    
            // page box
            $this->intPage = new QIntegerTextBox($this);
            $this->intPage->Width = 50;
            $this->intPage->AddAction(new QEnterKeyEvent(), new QServerAction('btnGo_Click'));
    
            // "go" button
            $this->btnGo = new QButton($this);
            $this->btnGo->Text = QApplication::Translate('Go');
            $this->btnGo->AddAction(new QClickEvent(), new QAjaxAction('btnGo_Click'));
            $this->btnGo->AddAction(new QClickEvent(), new QServerAction('btnGo_Click'));
            $this->btnGo->CausesValidation = true;
    }
    
    protected function btnGo_Click($strFormId, $strControlId, $strParameter) {
            $count = Signatory::CountAll();
            $pages = ceil($count / __FORM_DRAFTS_FORM_LIST_ITEMS_PER_PAGE__);
            if ($this->intPage->Text < 1) {
                    $this->intPage->Text = 1;
            } elseif ($this->intPage->Text > $pages) {
                    $this->intPage->Text = $pages;
            }
            $this->dtgSignatories->Paginator->PageNumber = $this->intPage->Text;
            $this->dtgSignatories->Refresh();
    }
    

    【讨论】:

      【解决方案3】:

      如果您的意思是从 UI 角度来看,分配一个 Paginator,然后在网页上显示 Paginator。请参阅 qcu.be 上有关数据网格的示例。

      在内部,您可以在数据绑定器中通过添加 QQ::Limit 子句以及所需页面的正确偏移量和大小来执行此操作。

      【讨论】:

      • 谢谢spekary。很抱歉这个模糊的问题。该问题已被编辑。我希望现在更清楚了。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多