Yii Framework Forum: Many hidden columns problem in CGridView - Yii Framework Forum

Jump to content

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

Many hidden columns problem in CGridView Rate Topic: -----

#1 User is offline   rei 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 332
  • Joined: 10-November 10

Posted 12 July 2011 - 10:51 AM

What I need to achieve is when users click a row in CGridView, its data (16 columns) is passed to parent window. We can achieve this by making all columns visible, but I have several columns that don’t need to be displayed in CGridView (although they still need to be passed to parent window).

I have tried:

array(
  'value'=>'...',
  'headerHtmlOptions'=>array('style'=>’width:0%; display:none'),
  'htmlOptions'=>array('style'=>’width:0%; display:none'),
)


array (
  'type'=>'raw',
  'value'=>'CHtml::hiddenField(…)',
  'htmlOptions'=>array('style'=>'width:0%; display:none'),
  'headerHtmlOptions'=>array('style'=>'width:0%; display:none')
),


These works if we have a few hidden columns. However, when there are many hidden columns, the CGridView becomes like the attached picture (there is a blank space on the right part of it).

Does anyone have solution for this?

Attached File  post2.jpg (107.17K)
Number of downloads: 68
Fipick - Find and pick recommendations
0

#2 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,359
  • Joined: 12-October 09
  • Location:Croatia

Posted 13 July 2011 - 04:06 AM

i don't know all the details... but if this parent window is anoter http request... it would be better to pass only the primary key of the selected row and then from the controller before rendering the parent window to search that record and get all the data needed...

on the other side.. .if you do this all on the client (no http request for the parent)... then you need to play a bit more... again you could get only the PK of the selected row... and all the other data from an ajax call to a specific method only for that...

third solution I can think of is to put all this "additional" data into one column that is hidden, all values separated by some delimiter

would be nice to hear how you solve this...
Find more about me.... btw. Do you know your WAN IP?
1

#3 User is offline   rei 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 332
  • Joined: 10-November 10

Posted 13 July 2011 - 08:39 PM

The parent window is called via Javascript (client side). Initially, I did something like this:

Yii::app()->clientScript->registerScript('row-click', "
$('#material-grid table tbody tr').live('click', function(){
  var parent = window.opener;

  parent.$('#BidDetail_wood’).val($(this).children(':nth-child(12)').text());
});
");


Quote

put all this "additional" data into one column that is hidden, all values separated by some delimiter


Yes, I go with this solution since it is easier than writing additional ajax call. The blank space on right side still appears, but it doesn’t look significant now.

Just post a summary for this (in case someone needs it :) ). The hidden CGridView column becomes somewhat like:

array(
  'value'=>'
	$data->category->name."|".
	$data->wood_construction."|".
	$data->purchased_place
  ',
  'headerHtmlOptions'=>array('style'=>'display:none'),
  'htmlOptions'=>array('style'=>'display:none'),			
)


While the script is pretty straightforward:

Yii::app()->clientScript->registerScript('row-click', "
$('#material-grid table tbody tr').live('click', function(){
  var parent = window.opener;

  // get hidden data value (hidden column is the seventh column)
  var data = $(this).children(':nth-child(7)').text().split('|');	

  parent.$('#BidDetail_category').text(data[0]);
  parent.$('#BidDetail_wood').text(data[1]);
  parent.$('#BidDetail_place').text(data[2]);
  ....
});
");



Thank you for your help, mdomba, as always. :)
Fipick - Find and pick recommendations
0

#4 User is offline   mshakeel 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 04-January 13

Posted 04 January 2013 - 01:43 AM

We need to have hidden fields in our columns for id columns in the database which can be accessible in the $_REQUEST so database can be manipulated. For this there is a simple solution which is as follows:

In any column which is visible to user one can have many hidden fields using the concatenation operator:

array(
            'header'=>'75%',
            'name'=>'field_name',
            'type'=>'raw',
            'value'=>
            'CHtml::hiddenField(\'array_available_in_request[\'.$row.\']["id"]\', $data["id"]) .
            CHtml::hiddenField(\'array_available_in_request[\'.$row.\']["parent_id"]\', $data["ParentId"]) .
            CHtml::textField(\'array_available_in_request[\'.$row.\']["field_name"]\', $data["field_name"], array("style"=>"width:50px;"));'
        ),

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