I am working on a Yii project,on the index page i have multiple div id's loaded by the yii the first id is named yw0 and second is yw1 and third is yw2,but after the yw1 id i have a ajax page which also generates two id's yw0 and yw1. so the new id's are conflicting with the old one what will will be the possible solution to get rid of this.
$this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dp,
'itemView'=>'_view',
'id'=>'id-of-list-view-div',
'pager'=>array(
'id'=>'id-of-pager-ul'
)
));
You can set your own html ID on both widgets (CListView and CPager)
This way when they are reloaded they will keep the IDs and there will be no conflict
Hope it helps
Related
I want to set items per page dropdown in yii gridview.
What changes i need to do this? Has anyone had implemented this type of functionality before?
You have to add summaryText entry to the gridview as below.
$pageSize=Yii::app()->user->getState('pageSize',Yii::app()->params['defaultPageSize']);
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$dataProvider_countries,
'summaryText'=>'Displaying {start}-{end} of {count} result(s). ' .
CHtml::dropDownList(
'pageSize',
$pageSize,
Yii::app()->params['pageSizeOptions'],
array('class'=>'change-pageSize')) .' rows per page',
Result is similar to following.
How I do not display empty and null rows in yiiframework with listview.
Many rows in database are null.When I want to show data in view.php I see many null rows.I see a data on the other page.
can I see just rows with data.
The CListView widget uses a template to render each row of data.
In the skeleton generated by Gii, the index.php file has a CListView widget that uses the _view.php file to display row data.
You only have to check if a field is null and don't show it.
If you are aking for the autogenerated view.php file, the default is CDetailView
At this place, you can use the "visible" element of the attribute item:
<?php $this->widget('zii.widgets.CDetailView', array(
'data'=>$model,
'attributes'=>array(
array(
'name'=>'field1',
'visible'=>$model->field1!=null,
),
..............
See attributes property of CDetailView and CListView
in your model, put a condition to filter null/empty values before rendering the result to your view.
public function search() {
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
$criteria->compare('table_column', $this->tableColumn, false );
$criteria->condition .= "another_table_column IS NOT NULL"; //this will filter null values
Use the afterFind() method in your Model to change the value displayed in the view so that a null value is shown as "NA" or some other value like that.
I merge create and admin views and method in my controller,
so in admin.php I have following lines:
echo $this->renderPartial('_form', array('model'=>$create));
echo $this->renderPartial('_admin', array('model'=>$search));
and in _form I edit submit button to
echo CHtml::ajaxSubmitButton('Submit', Yii::app()->createUrl('money/income'), array('update' => '#money-grid'));
and in money controller,income method implement create method and send CGridView as ajax response.
if ($createModel->save()) {
$this->renderPartial('_admin', array('model' => $searchModel), false, true);
if data saved into database,it render _admin view which contain CGridView,this works prefect ,but problem exist, if client create something and insert into database, so after it click on delete of CGridView it will trigger more than one and it makes problem,
for example if user insert n rows ,then click on the each row to delete,it will trigger n + 1 times.(but it should be 1)
where is the problem?is it for Yii?
The problem solved by updating CGridView by jQuery instead of rendering it,so I changed my ajaxSubmitButton to
echo CHtml::ajaxSubmitButton('Submit', Yii::app()->createUrl('money/income'), array('success'=>'$.fn.yiiGridView.update("money-grid")'));
and it solved problem.
'success'=>'$.fn.yiiGridView.update("money-grid")'
I'm using boostrap library on Yii via yii-booster
I've created a relation table view
The related view is a TbGriView itself
Vhen in a row i click on the link on the 'related' column, the row expands itself, and render a TbGridview inside it.
The problem is that the internal gridview cannot be sorte, paged or filtered, because each action on it causes that the entire container grid will empty
Note
- external grid as a id of 'extenalgrid'
- each internal grid has as id like 'internalgrid-$rowId' , so every internal grid as differnt id on div, table and table row elements.
- the action called from "render related tabel" link is using renderPartial without the postProcess option. If i use potProcess, the row will be empty
So is it not possible to rendere a full working gridview/tbgridview into a related table ?
Use different css classes for the filters, buttons and headers for the different tables. From the jquery.yiigridview.js file events are bound to selectors as $('#table-id .selector-class') so elements in your internal gridView still trigger the events bound to the external gridView. You also have to specify a different url for the internal gridView by setting it's ajaxUrl.
i got a problem while updating a record for a model in yii. i have 2 models. im working on one model now. I'm creating a record for one model using create controller. in the form i've 1 fields which is the name field(im getting this name from other model(table). im getting the names from this second table and showing them in dropdown list. and storing them.
when it comes to update its again coming up with the same dropdown what i've shown using the _form.php for creating a record. can anyone pls tell me how can i show the name instead of dropdown list again??
thanks in advance.
Add a simple check in your view to see if the value has already been added or not. Something like this:
<?php if ($model->attribute && $model->attribute != ''): ?>
// Code to display a normal textfield here
<?php else: ?>
// Code to display dropdown
<?php endif; ?>