Problem
This problem is regarding Yii2 project which should show relevant Recipient list when click on the User Group name.
At the moment I have created all the databases, models, CRUD generations with gridviews & working perfectly. But the problem is when I click on the grid item it navigates to another view (the default way) as following pic which I want to load in a part of the same view.
User-groups (view -> index.php)
<?php Pjax::begin(); ?>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
//navigate to the relevent recipient list by click on the group name
'rowOptions' => function ($model, $key, $index, $grid) {
return [
'style' => "cursor: pointer",
'id' => $model['group_id'],
'onclick' => 'location.href="'.Yii::$app->urlManager->createUrl('recipient-list/recipients').'&scenario=RECIPIENTS¶ms="+(this.id);',
];
},
'columns' => [
'group_id',
'group_name',
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
<?php Pjax::end(); ?>
I have given the rowOptions in the GridView so that the record can be clicked & navigate to the recipient list through the URL. Then that will be captured from the controller & filter the result according to group_id & render the view.
What I want
I want to dynamically load the recipient list when click on the left side group list.
I have tried
iFrames but it is not working properly. it works as a separate tab in the browser.
added many Yii navigation extensions like sideNavs by kartik for group list. But the problem was it haven't the ability to getting data from database. when I create a group it didn't show in the list. (It is good if the side nav was static)
So .. What I want to know is, is there are any way to do this with the controller or is there any Jquery code to support this...
any suggestions or references are warmly welcome.
you can use jQuery .load for this.
lets say your recipient list container div has a id of #recipient-list so all you have to do is add the following on your onclick event:
$( "#recipient-list" ).load("YOUR_URL"); return false;
// replace YOUR_URL with the url you are generating already
// and don't forget the return false part. it't there so that link doesn't redirect
When you click in the row, on click event
you will make an ajax request to retrieve the
data for the second grid (Recipient List)
on success or complete of ajax request
you will call $.pajax.reload to refresh
the data in second grid like this
$.pjax.reload({container:'#recipient-list'});
Related
How can I edit the _search view (which is implemented by Yii2 Crud Generator), so that I can make two form fields on the same line?
(Note that I have resized the form fields to 500px so that they can fit one line).
Also, I would like the 'Search' and 'Reset' buttons to be on the same line too.
You can use options and assign eg: a proper twitter-bootstrap grid width
this way :
<?php echo $form->field($model, 'your_filed', ['options' => ['class' => 'col-md-4', ]]) ?>
I have a problem with dynamically reloading of areas in html file. I use an Ajax based approach. I successfully update the area of my interest (HTML div tag), but every time I do an update the same JavaScript gets downloaded and processed along with the replacement html code, which consumes time. I want that browsers reuse, on AJAX update, the last downloaded JavaScript file instead fetching its same content again and again, which results in excessive overhead. What I mean? Let's say I have a Button Widget which has widget.js JavaScript attached to it. This JavaScript will be responsible for the event triggered on button click. Every time this button is clicked, the event will 'shoot' AJAX request and particular area on HTML page gets updated along with a download of widget.js if necessary. I want that widget.js is downloaded only the first time, but currently it gets downloaded on every AJAX request. What I noticed is that every time the mentioned JavaScript file is requested with an appended query parameter _ with random value.
widget.js?_=1374504824837
How can I disable this random parameter?
my index.php
<p>
<div id='widget-container'>
<?php
$this->renderPartial('widget');
?>
</div>
</p>
my controller
public function actionWidget()
{
$this->renderPartial('widget',array(),false,true);
}
my widget.php
<?php
$url = 'widget';
$update = '#widget-container';
$this->widget('ext.bootstrap.widgets.TbButton',
array('label' => 'Widget',
'size' => 'medium',
'buttonType' => 'ajaxButton',
'url' => $url,
'ajaxOptions' => array('type' => 'POST',
'update' => $update,
'cache' => false),
'htmlOptions' => array('id' => 'widget'.uniqid())
)
);
?>
There is an extension NLCClientScript, that is to prevent duplicated linking of javascript files when updating a view by ajax, replacing Yii's original ClientScript class.
Slightly different approach is to turn processOutput of renderPartial to false, but, in this case it won't embed any js at all
$this->renderPartial('widget', array(), false, false);
I am using a CActive Form and, earlier i was having a normal submit button. Then I changed it to an Ajax Button like as follows,
CHtml::ajaxSubmitButton('Continue',CController::createUrl('//shop/order/create&store=true'),array('type'=>'POST'));
This goes to the url when u refresh the page. But i want it to go to the page without page refresh. Any idea how do it?
Thanks in advance.
try this, with some ajax success functionallity...
echo CHtml::ajaxSubmitButton('BottonLabel',
Yii::app()->createUrl('your/url',array('calltype' => 'system')),
array('type' => 'POST',
'cache' => true or false,
'success' => 'js:function(data) {yourJSfunction(data)}'),
array('id' => 'the_id'));
or follow this link to the class-reference for yii
ajaxSubmitButton
try this..
array('contoller_name/action','ajax'=>'somevalue'));
//In your case
echo CHtml::ajaxSubmitButton('Continue',array('contoller_name/action','ajax'=>'yw0'));
Just keep in mind that you are obviously setting auto created widget ids as params (yw0). You should assign your own ids to widgets, otherwise another widget could have the same id and that can be hard to debug..
Im building a web app using the yii framework. I have a dropdownlist and im calling an action and updating a div tag using ajax array 'update'=>'#price' field. the code works fine and it updates the price div.
But i want to update two fields like that, i tried passing an array to the update field. but it didnt work.
Any Idea how I can update two div tags and show two values using one action call?
Heres My Code..
echo CHtml::beginForm();
echo CHtml::dropDownList('amount_'.$position,'', array(1=>1,2=>2,3=>3),
array(
'ajax' => array(
'type'=>'POST',
'url'=>CController::createUrl('shoppingCart/updateAmount'),
'update'=>'#price_'.$position, //selector to update
)));
echo CHtml::endForm();
and in my action im just echoing
echo 'LKR '.Shop::priceFormat(#$product->getPrice($cart[$position]['Variations'], $value));
It'll be great if someone could help.
It's simply jQuery selector. I believe you can use comma for few ids. Or you can use class selector. (I think class selector would be better here)
'ajax' => array(
/* ... */
'update' => '#price_1, #price_2, #price_3',
/* or */
'update' => '.price'
)
I have the following code in my index.ctp view to create a form:
<?php
echo $this->Form->create(false,array('url' => array('controller' => 'admins', 'action' => 'edit_gallery')));
echo $this->Form->input('name', array('options' => $array,'empty' => 'Select a gallery'));
echo $this->Form->end(__('Submit', true));
?>
Thi codes creates a dropdown list of items, each one with an associated number as value.
In my admins_controller I have the edit_gallery action implemented exactly as it comes when you bake a project, only that I changed the typical edit to edit_gallery.
What I want is the following: the user selects one item from the list, then clicks 'Submit', and he's taken to the edit_gallery.ctp view, with a form to edit the information of that item in the database and update it. My problem is that, instead of doing this, what happens is that when the user clicks Submit, a new item is created in the database, and it doesn't even show the ctp view.
In general, my question would be: how can I get the selected option of the form in the landing page after the user clicks 'Submit'?
Edit
Ideally, what I would want is that, when the user clicks 'Submit', it would send a request like admins/edit_gallery/x where x would be the value associated to the selection made by the user, without sending any other data to the action. I don't know if that's possible.
Thank you!
The edit method that CakePHP bakes check by default if data is not null, in other words, if a form has been submitted, and then updates that record.
So, when you redirect to *edit_gallery* from a form, the data property is not null, therefore the reason for the new item creation in the database.
There are many ways to solve this. One of them is to remove that check from the *edit_gallery* method, create another method like *save_gallery*, and call that method from *edit_gallery.ctp*.
So the *edit_gallery.ctp* form would look something like:
<?php
echo $this->Form->create(false,array('url' => array('controller' => 'admins', 'action' => 'save_gallery')));
(your form info)
echo $this->Form->end(__('Submit', true));
?>