Post details: Button to "Select All" checkboxes in P4A

10/12/09

Permalink 02:27:05 pm, by admin Email , 171 words, 2703 views   English (US)
Categories: PHP

Button to "Select All" checkboxes in P4A

Given the following which creates a set of checkboxes:

$db =& P4A_DB::singleton();
$clientlist = array();
$items = $db->fetchAll("SELECT * FROM microsites WHERE status=1 ORDER BY sitetitle");
foreach ($items as $item) {
$ci = $item['user'];
$cd = $item['sitetitle'];
$clientlist[] = array('id' => $ci, 'desc' => $cd);
}

$client_array_source =& $this->build("p4a_array_source", "client_array_source");
$client_array_source->load($clientlist)
->setPk("id");


$selectallbutton = $this->build("p4a_button","selectallbutton")
->setLabel('Select All');
$this->intercept($selectallbutton, 'onClick', 'selectall');

$this->build("p4a_field","clients")
->setWidth(300)
->setType("multicheckbox")
->setSource($client_array_source)
->setSourceDescriptionField("desc")
->setSourceValueField("id");

This function will allow the user to click the "select all" button and have their checkboxes populated:

function selectall() {
$array_id = array();
$num_rows = $this->clients->data->getNumRows();
for ($i = 1; $i $#60;= $num_rows; $i++) {
$this->clients->data->row($i);
$array_id[$i] = $this->clients->data->getPkValues();
}
$this->clients->setNewValue($array_id);
$this->clients->load();
}

This works in P4A v3.4.1 but not 3.4.0. I've not tested on later versions.

Trackback address for this post:

http://www.fearofmice.co.uk/blog/htsrv/trackback.php?tb_id=44

Comments, Trackbacks, Pingbacks:

No Comments/Trackbacks/Pingbacks for this post yet...

Comments are not allowed from anonymous visitors.

fear of mice

This is the official blog of

We aim to post comments (and possibly solutions) to some of the more interesting IT Support issues we come across in our daily travels around the South Hams of Devon.

September 2010
Mon Tue Wed Thu Fri Sat Sun
<< <     
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30      

Search

Categories

Misc

XML Feeds

What is RSS?

Who's Online?

  • Guest Users: 2

powered by
b2evolution