Yii Framework Forum: Help needed to display data in table format - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Help needed to display data in table format using CGrid View Rate Topic: -----

#1 User is offline   gauviz 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 22-June 10

Posted 18 November 2010 - 06:44 AM

How do i display data in table format using CGridView.
I have already changed view.php as follows
$dataProvider=new CActiveDataProvider('Expense');
$this->widget('zii.widgets.grid.CGridView', array(
    'dataProvider'=>$dataProvider,
));

now what should i have in _view.php to display it in Tabluar format.

Also is there a way to provide default values in $form->textfield

I'm just starting with Yii. Help appreciated

Thanks
0

#2 User is offline   Dana 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 245
  • Joined: 18-February 10
  • Location:Florida, USA

Posted 18 November 2010 - 08:06 AM

You need to tell the widget which columns you want the table to have:
$this->widget('zii.widgets.grid.CGridView', array(
    'dataProvider'=>$dataProvider,
    'columns'=>array(
        'modelProperty1',
        'modelProperty2',
        'modelProperty3',
    ),
))


For the form, you can have it display the value that's currently set in the model by using the CActiveForm widget for the $form.
	<?php echo $form->labelEx($model,'modelProperty1'); ?>
	<?php echo $form->textField($model,'modelProperty1'); ?>
	<?php echo $form->error($model,'modelProperty1'); ?>


I believe there are some good examples of how to use the CActiveForm widget in the Cookbook section.
0

#3 User is offline   Devmurari 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 07-March 16

Posted 08 March 2016 - 03:53 AM

View PostDana, on 18 November 2010 - 08:06 AM, said:

You need to tell the widget which columns you want the table to have:
$this->widget('zii.widgets.grid.CGridView', array(
    'dataProvider'=>$dataProvider,
    'columns'=>array(
        'modelProperty1',
        'modelProperty2',
        'modelProperty3',
    ),
))


For the form, you can have it display the value that's currently set in the model by using the CActiveForm widget for the $form.
	<?php echo $form->labelEx($model,'modelProperty1'); ?>
	<?php echo $form->textField($model,'modelProperty1'); ?>
	<?php echo $form->error($model,'modelProperty1'); ?>


I believe there are some good examples of how to use the CActiveForm widget in the Cookbook section.


Perfect solution for newbi in YII , I had facing same issues but this solution is very helpful for me.... :) Thanks to Dana....
0

#4 User is offline   azzafirdaus 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 24-April 15
  • Location:Indonesia

Posted 10 March 2016 - 04:37 AM

Thanks it works :rolleyes:
0

#5 User is offline   PUNKER 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 18-July 17

Posted 18 July 2017 - 03:03 AM

View PostDana, on 18 November 2010 - 08:06 AM, said:

You need to tell the widget which columns you want the table to have:
$this->widget('zii.widgets.grid.CGridView', array(
    'dataProvider'=>$dataProvider,
    'columns'=>array(
        'modelProperty1',
        'modelProperty2',
        'modelProperty3',
    ),
))


For the form, you can have it display the value that's currently set in the model by using the CActiveForm widget for the $form.
	<?php echo $form->labelEx($model,'modelProperty1'); ?>
	<?php echo $form->textField($model,'modelProperty1'); ?>
	<?php echo $form->error($model,'modelProperty1'); ?>


I believe there are some good examples of how to use the CActiveForm widget in the Cookbook section.

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users