Showing posts with label PHP. Show all posts
Showing posts with label PHP. Show all posts

Thursday, January 1, 2009

P4A Table, a delete row helper

Sometimes, when I work with P4A, I prefer to allow the deletion of a record with a click on the table row. Look at this screenshot to have an idea:



Doing that with P4A is not hard: you have to add an action col, intercept the afterClick event and then call the db_source deleteRow event. Yet now it's even simpler because we have added the addDeleteRow helper to the P4A core :


$mytable->addDeleteRow();



If you want you can also call the helper with a custom label col and a custom confirmation message:



$mytable->addDeleteRow('Delete Row','Do you want to delete this row?');


You can find this helper in the svn repository or you can copy and past my code in the libraries directory:


<?php
function P4A_Table_addDeleteRow($table$params)  
{      
    if (isset(
$params[0])) {
        
$col_label $params[0];
    } else {
        
$col_label 'Delete';
    }
        
    if (isset(
$params[1])) {
        
$message $params[1];
    } else {
        
$message 'Delete current element';                   
    }

    
$table->addActionCol('delete');
    
$table->cols->delete->setWidth(150)
                        ->
setLabel($col_label)
                        ->
requireConfirmation('onClick'$message);
    
$table->data->intercept($table->cols->delete,'afterClick','deleteRow');

    return 
$table;
}


Happy P4A hacking!

Sunday, December 28, 2008

P4A 3.2 is out!

Yes, P4A 3.2 is finally out!

The Changelog is really long but there are 3 big news to focus on:
  1. P4A is now released under LGPL 3. This means more flexibility for developers and customers.
  2. A new widget, the P4A_Grid, has been added to fast table data editing.
  3. P4A_Simple_Edit_Mask has been added to quickly create a simple mask to edit a database table.

To download P4A 3.2 visit:
http://sourceforge.net/project/showfiles.php?group_id=98294&package_id=105252&release_id=647599

Happy P4A hacking :)

Saturday, October 11, 2008

Big news for the incoming P4A 3.2

Yes, big news for the incoming P4A 3.2

I've just finished to commit the first beta release of a new widget: the p4a_grid.
What is it? It's simply an editable table. This widget has been for a lot of time a highly requested feature so now I'm really happy to have it :) There's a lot of work to be done to have the perfect widget, for example to add checkbox cells and combo box cells, but now it already does a good job.

Using the p4a_grid is similar to using the p4a_table:

$this->build("p4a_grid", "grid")
->setWidth(600)
->setSource($this->source)
->setVisibleCols(array("product_id", "model", "date_arrival", "category", "brand"));

Now you have two options:

1) Using the "autosave" method to save automatically the changed values to database

$this->grid->autosave();

2) Intercepting the onChange event if you need to add more complex business logic:

$this->intercept($this->grid,'onChange','myhandler');
...
function myhandler($obj,$params){
/*
$params[0] -> the primary key value
$params[1] -> the column name
$params[2] -> the formatted new value
$params[3] -> the unformatted new value
*/
...
}

If you want to try it checkout it from svn and please give me your feedback :)