Checkbox in p4a_table

  • Dmitry

    Dmitry - 2009-07-30

    Hi All!

    I've implement some functionality I'd like to share with other p4a developers.
    Sometimes it is useful to select multiple rows in a table for some butch processing. Following class  utilize 'action' column feature to make rows selectable.
    You can use this code as workaround  until this feature be implemented in base P4A_Table
    Any extensions of this code are welcome. :)


    class SelectableRowsTable extends P4A_Table


        protected $selected_rows = array();

        protected $pk= null;



         * @param string $name Mnemonic identifier for the object


        public function __construct($name)





        public function addSelectCol(){



            $this->pk = $this->data->getPk();

            if ($this->pk !== null) {

                $this->cols->build('p4a_table_col', $column_name);


                if (!empty($this->_cols_order)) {

                    $this->_cols_order[] = $column_name;







            return $this;



        public function isRowSelected($pk){

            return isset($this->selected_rows[$pk]);



        public function getSelectedPks(){

            return $this->selected_rows;



        public function getRows($num_page, $rows)


            $tmprows=$this->rows->getRows($num_page, $rows);


            $id = $this->getID();

            foreach($tmprows as $i => $row){

                foreach($row['cells'] as $j=>$cell){



                    $tmprows[$i]['cells'][$j]['value']= "<input type='checkbox' id='{$id}input' name='test' value='{$pkvalue}' ".(isset($this->selected_rows[$pkvalue])? "checked/>":"/>");

                    $tmprows[$i]['cells'][$j]['action']= $this->cols->selectaction->composeStringActions( array($i, 'Selectaction', $pkvalue));




            return $tmprows;



        public function invertSelection($param1,$param2){



            } else $this->selected_rows[$param2[2]]=true;       



  • Anonymous - 2011-01-17

    This is very useful,
    BTW, any trick to move the checkbox to first column. Thanks


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks