neurotic imbecile
neurotic imbecile

Reputation: 31

Jump to a specific page in a QDataGrid

Please note that this question is specifically for the QDataGrid feature of the QCubed PHP framework. The API documentation for QDataGrid does not describe any feature that answers this question. The QCubed samples site also doesn't have a solution for this.

Question:

Sometimes a QDataGrid has more than a hundred pages. Is there a way to jump to a specific page in a multi-page datagrid?

For example, there's a QDataGrid with 167 pages. The QPaginator only shows:

Previous | 1 2 3 4 5 6 7 8 ... 167 | Next

So if the user wants to go to page 100, he has to do a lot of clicks. (I know the QDataGrid can be filtered and sorted, but there are times when those are of little help).

I'm thinking of adding a "jump to page" QTextbox, but how would I tell QDataGrid to the page specified in the textbox?

Upvotes: 0

Views: 156

Answers (3)

Harshith Cariappa
Harshith Cariappa

Reputation: 79

U can use this pagination in your code to get that

    $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);

In SetDataBinder u call the function.

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

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

}

the TotalItemCount takes the count which is used in the pagination and iteration and the Datasource will have the data which can be shown in the datagrid.

Upvotes: 1

neurotic imbecile
neurotic imbecile

Reputation: 31

I finally found a way to do this using qcubed, maybe it can help someone in the future. Basically, I just added a QIntegerTextBox and a QButton in the Form_Create() function, and I added an action to set a value for the QDataGrid's Paginator->PageNumber property. Like this:

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();
}

Upvotes: 0

spekary
spekary

Reputation: 438

If you mean from a UI perspective, assign a Paginator, and then show the Paginator on the web page. See the Examples on datagrids at qcu.be.

Internally, you would do that in your data binder by adding a QQ::Limit clause with the correct offset and size of the page that you want.

Upvotes: 0

Related Questions