MetaDataBinder and Pagination

thread: 6 messages  |  last: a year ago  |  started: wednesday, september 8, 2010, 5:43 am pdt


#1  |  gr2712
Wednesday, September 8, 2010, 5:43 AM PDT

Hello, I have a small problem with a MetaDataGrid, performing a re-bind (for a search) and Pagination.

In the Constructor, the Datagrid and Pagination is defined:


$this->dtgPersonen = new PersonDataGrid($this);
$this->dtgPersonen->Paginator = new QPaginator($this->dtgPersonen);
$this->dtgPersonen->ItemsPerPage = 20;

To perform a quick search over the data, a Textbox and a Button exist with the following code.

protected function btnQuicksearch_Click($strFormId, $strControlId, $strParameter) {

        $this->dtgPersonen->MetaDataBinder(QQ::OrCondition(                                                         /* my condition */ ), QQ::Clause(QQ::Distinct()));
        
        $this->btnClear->Enabled = true;
               

    }

It works fine, calling this method filters the data by the specified condition and the datagrid displays the first page properly, including Pagination data (“Show 10 records of 81” with 81 being the rows matching the cond.).

However, if a user clicks on the “2” to advance to the second page, not the second page of the result set is shown, but the second page of all rows, similar to BindAllRows() being called.

Clicking the Quicksearch button again on the second page shows the correct second page of the result set.

Did I miss something or is this a Paginator bug?

#2  |  Gaspar Attila (Odorheiu Secuiesc, RO) Romania
Wednesday, September 8, 2010, 7:03 AM PDT

Hello gr2712

My suggestion is set your own databinder to the datagrid and, change the condition if QuickSearch clicked.

So, add this to your datagrid:


$this->dtgPersonen->SetDataBinder('dtgPersonen_Bind');

.bc 

then make the binder function:

bc.

public function dtgPersonen_Bind(){
     $this->dtgPersonen->MetaDataBinder($this->objCondition, $this->objClause);
}

Note: define the $objCondition and $objClause in the top of the class and set their default value which is used if QuickSearch not clicked.

Now modify the click event handler:


protected function btnQuicksearch_Click($strFormId, $strControlId, $strParameter) {
       $this->objCondition = QQ::OrCondition(  /* my condition */ );
       $thid->objClause = QQ::Clause(QQ::Distinct());

        $this->btnClear->Enabled = true;
        //Refresh datagrid
        $this->dtgPersonen->Refresh();
}

P.S. Sorry for my bad english.

Regards,
Attila

#3  |  gr2712
Wednesday, September 8, 2010, 7:46 AM PDT

Thank you, this worked perfectly :)

However, this still seems to be a bug with the MetaDataBind() methods - the datagrid “forgets” the current binding and reverts to BindAllRows instead when a page is clicked - unless the workaround described by Attila is used.

#4  |  Mike Ho (Sunnyvale, CA) United States of America Qcodo Administrator
Wednesday, September 8, 2010, 9:23 AM PDT

First of all, note that Gaspar's post on using a separate data binding method isn't a “workaround” -- it's actually the way DataGrids are supposed to be used (be sure to check out the Examples Site for more).

Second, it might be a better idea to set up the condition and clause in your databinder method itself... that should resolve the issue that you have with the condition and clause being “forgotten” in some cases.  In general, you should keep databinding-related logic in your databind method (makes sense, doesn't it? =)

#5  |  gr2712
Thursday, September 9, 2010, 2:17 AM PDT

Hmm, I thought there's a difference between Datagrids and Metadatagrids in their “binding best practice”, but always using SetDataBinder seems to be the way to go.

Anyway, thanks for the input - still learning =)

#6  |  Mike Ho (Sunnyvale, CA) United States of America Qcodo Administrator
Thursday, September 9, 2010, 9:55 AM PDT

Yeah... the best practice for DataGrids and MetaDataGrids is to use SetDataBinder.  The only difference with MetaDataGrids is that they include that code generated metadatabinder helper method to make your data binder method code simpler. =)



Copyright © 2005 - 2012, Quasidea Development, LLC
This open-source framework for PHP is released under the terms of The MIT License.