How can I guide you? You need to help me so that I can help you
Describe what you need to do… and post your code…
But first try to search a bit on the forum… I think there are some posts about that…
How can I guide you? You need to help me so that I can help you
Describe what you need to do… and post your code…
But first try to search a bit on the forum… I think there are some posts about that…
hi Mdomba
I want to pass more info in the selected rows when user click.
Let say for $.fn.yiiGridView.getSelectionb,when user click the 1st rows, the (target_id only get the key value for the selected row. How to get the full_name and depart info when user click the selected row and print it out??
Please Helps.
$this->widget('zii.widgets.grid.CGridView', array(
'id' => 'detail-grid',
'selectableRows' => '2',
'dataProvider' => $dataProvider,
'columns' => array(
array(
'class' => 'CCheckBoxColumn',
'id'=>'ids'
),
array(
'name' => 'id',
),
array(
'name' => 'full_name',
),
array(
'name' => 'department',
),
array(
'class' => 'CButtonColumn', //default
),
),
))
;
<script type="text/javascript">
function userClicks(target_id)
{
// need write what to get more value in the selected rows...........
alert($.fn.yiiGridView.getSelection(target_id));
}
</script>
<div id="id_view"></div>
What you want to do with this data? I mean where do you need the full_name?
If you need to send that to the server… then maybe you need to revise your logic… because if you send the primary key to the server… you can get the record from the database…
On the other hand… if you need the full_name on the client to process it with JS/jQuery, then again you need to revise your logic… as in that case you don’t need the primary key ID… so you don’t need the getSelected() at all… in this case… you need to write a custom script and bind it to the TR rows and “read” the needed values from the grid columns… here is a thread that has a similar need with an idea for the solution - www.yiiframework.com/forum/index.php?/topic/13804-
Hi Mdomba,
For example,
i got a list of users, i only click 2 selected users in Ccheckboxcolumn CGridView and pass their info that contains id, full_name and department to another pages to view. How to retrieve the info? Needs using JS/JQuery? Please guide me
Thanks,
You are really not helping too much… what means to you "pass the info to another pages to view"…
To me it means that you call the server (controller/action)… that is the first case that I wrote above… in this case you just need to send the IDs… and then in the controller you can search the database to get the other info you need…
Hi Mdomba,
Sorry for my lousy english…
i mean when user click 2 row record in CCheckBoxColumn. I want render to another pages and get the 2 record info with id, full_name and department for viewing purpose.
To me it means that you call the server (controller/action)... that is the first case that I wrote above... in this case you just need to send the IDs... and then in the controller you can search the database to get the other info you need...
Is there anyway to avoid searching the database again to get the info?? Since the previous page i already get the info… Sorry again if my question is nonsense.
Thanks again for help.
It can be done with jQuery… but is not really easy… it’s better to search again… that’s why you get the primary keys…
Thanks Mdomba,
how to pass the
($.fn.yiiGridView.getSelection(target_id))
to another page/action if user select more rows since JQuerynot really easy? Pls give me some example to work on.
Thanks again for your helpss.
=)
Fist of all you need to decide how will the user decide when to go to the next page… he selects the rows he needs… and then?
Will there be a button that the user needs to click for this? If yes… then in that button handler you call the getSelected() and send the IDs as parameters…
Hi Mdomba,
If yes.. then in that button handler you call the getSelected() and send the IDs as parameters...
Emmm. How to call the getSelected() and send the IDs as parameters??? I still newbie.
I wonder the previous code in this topic can use for my situation?? the method type suppose is post or get in CCheckBoxColumn CGridView??
<?php echo CHtml::ajaxSubmitButton("Show Selected",
$this->createUrl('/account/DoChacked'),
array("type" => "post", //method type-- post or get?? right
"data" => "js:{chk:$.fn.yiiGridView.getSelection('gridcust')}",
"update" => "#output")); ?>
<div id="output"></div>
<?php
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$model,
'id'=>'gridcust',
'selectableRows'=>2,
'columns'=>array(
array(
'class'=>'CCheckBoxColumn',
),
array(
'header'=>'Customer Name',
'value'=>'$data[firstname]." ".$data[lastname]',
),
),
));
controller:
public function actionDoChacked(){
//if(Yii::app()->request->isAjaxRequest){
if(isset($_POST['chk'])) {
print_r( $_POST['chk']);
foreach($_POST['chk'] as $val) {
echo $val . '<br/>';
}
}
//}
}
This code makes an ajax call… and refreshes part of the current page with the data returned…
Instead of ajaxSubmitButton… use a submitButton so that the new page is opened…
in that code you can see how the getSelected is used… and how the data it returns is sent as a parameter…
post or get… is up to you… learn about them, what is the difference and then use what is better for your case…
Thanks Mdomba,
will try work on it!!! Hopefully can got solution.
Thanks again for spending your time in this topics. =)
I have this in my view:
<?php
echo CHtml::dropDownList('milestoneDrop',
0,
$this->getMilestoneSelectListFromIdentifier(),
array('empty' => 'No Milestone'));
?><?php
echo CHtml::ajaxLink("Set Milestone",
$this->createUrl('massEdit'),
array("type" => "post",
"data" => "js:{ids:$.fn.yiiGridView.getSelection('issue-grid'),val:$('#milestoneDrop').val(),type:'milestone'}"
)); ?>
Controller code:
public function actionMassEdit() {
if(Yii::app()->request->isAjaxRequest){
if(isset($_POST['ids'])) {
foreach($_POST['ids'] as $val) {
switch($_POST['type']) {
case 'milestone':
$issue = $this->loadModel($val, true);
$issue->milestone_id = $_POST['val'];
// some other stuff...
}
break;
default:
break;
}
}
}
}
}
good example ! useful to someone
Does anybody know is it possible to get programmatically precise value of column id of CGridView?
I don’t want to use hardcoded value such ‘my-grid_c0’ when I call
$.fn.yiiGridView.getChecked('my-grid', 'my-grid_c0')
to get checked boxes from zero column.
Thank you so much
hi
i suggest that see this link. it`s right wirked!!!
My link