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!

6 comments:

Andrea said...

Thanks for the bug report. I try to fix this issue before the next release :)

Anonymous said...

Andrea,

Could you post the Css code to make the delete columns looks like yours?

Please.


Eddie

Anonymous said...

Dear Andrea,

Great feature!
Same like Eddie, could you post the css code to make the delete columns looks like yours?

Thanks

Andrea said...

It's this :)


.p4a_table a {
padding:5px;
}

.p4a_table .action{
padding-left:10px;
}

.p4a_table tr:hover td {
background:#4b718a;
}

.p4a_table tr td.action:hover {
background:#c6d3de;
}

.p4a_table tr:hover td a {
color:white;
}

.p4a_table tr td.action:hover {
background:orange;
}

.p4a_table tr td.action:hover a{
color:#0b315a;
text-decoration:none;
}

Anonymous said...

Dear Andrea,

Thanks a lot!.
It works nicely :-)

Btw, just curious.
How should I add the CSS code?
Should I added it to the ..\p4a\themes\default\screen.css.php? (this is what I did)

Or maybe P4A has some kind of CSS override/adding system?
This is so that every time we upgrade P4A, it won't erase the customized css code.

Thank you.

Anonymous said...

Who knows where to download XRumer 5.0 Palladium?
Help, please. All recommend this program to effectively advertise on the Internet, this is the best program!