search qdatagrid (sort problem)

Login or register to post comments
2 replies [Last post]
Offline
Joined: 11/27/2009

hi everybody, i have a problem filtering in qdatagrid. I'm not using QFilterDataGrid because i would like to know how to filter without filters for default, then i'm creating a qtextbox to filter and show in the qdatagrid; i want to filter for name, then in my customer table in the file customerDataGrid.class.php, i wrote this method to filter for customer names(i just overwrite the MetaDataBinder method to filter for name):

public function MetaDataBinder_Filter($strName) {
                $objConditions = $this->Conditions;
                if(null !== $this->conAdditionalConditions)
                        $objConditions = QQ::AndCondition($this->conAdditionalConditions, $objConditions);

                // Setup the $objClauses Array
                $objClauses = array();

                if(null !== $this->clsAdditionalClauses)
                        $objClauses = $this->clsAdditionalClauses;

                // Remember!  We need to first set the TotalItemCount, which will affect the calcuation of LimitClause below
                if ($this->Paginator) {
                        $this->TotalItemCount = Cliente::QueryCount(QQ::Like(QQN::Customer()->Name, $strName. '%'), QQ::Clause(QQ::OrderBy(QQN::Customer()->strName)));
                }

                // If a column is selected to be sorted, and if that column has a OrderByClause set on it, then let's add
                // the OrderByClause to the $objClauses array
                if ($objClause = $this->OrderByClause)
                        array_push($objClauses, $objClause);

                // Add the LimitClause information, as well
                if ($objClause = $this->LimitClause)
                        array_push($objClauses, $objClause);

                // Set the DataSource to be a Query result from Cliente, given the clauses above
                $this->DataSource = Customer::QueryArray(QQ::Like(QQN::Customer()->Name, $strName.'%'), QQ::Clause(QQ::OrderBy(QQN::Customer()->Id)));
            }

In my customer_list.php, i use this function in this way to filter:

$this->dtgCustomers->MetaDataBinder_Filter($this->txtCustomerFilter->Text);

initially it's correct, my filter works! but if i clicked in the header to order for name, id or other field in the qdatagrid show me all customer witouth filter i don't know why. For example i have 20 customers in my qdatagrid, then i write in the txtCustomerFilter "carolyn" and filter, this return a list of 3 customer in my qdatagrid(my filter work but...), after this i would like to sort for name then i click in the name header, if i click in the name header to sort my qdatagrid this return me a list of 20 customer without filter, this is my problem, if i sort for any field this return me all customer of my table.
I would like to know how could do this or some way to filter without use the filter for default. Also i would like to know if what i'm doing it's correct.
Any suggestion?
Thanks for your time

Offline
Joined: 03/31/2008

When you change sort order, the data bind function is called again. Your problem is that this second time it's called, nothing is passing in $strName.

If you instead store it as a form variable, and use that within your bind function, it should be set the whole time.

Offline
Joined: 11/27/2009

yes, i forgot to call to SetDataBinder method, for this reason always return me all rows without filter.. thanks vexedpanda