My clients don’t need to see a primary key id displayed in their data, so I needed the id value to be there, but neither the header nor the data column to be displayed.
I used jquery to hide the id column in my grid.
jQuery(function($) {
/**
* Need to hide the id column
*/
grid = $('#level-grid');
$('tr', grid).each(function() {
$('td:eq(0), th:eq(0)',this).hide();
});
});
This method doesn’t require any changes to the controller or the model, The header row is lined up normally.
To remove the filter you just need to set the filter property to false…
CGridView already stores the primary key values in the generated page… you can get the primary key value for the selected row(s) with $.fn.yiiGridView.getSelection()
I’m also running into this problem. You can use headerHtmlOptions / htmlOptions to “display:none;”, but it doesn’t hide the filter. I want to be able to show/hide columns on the fly.
Removing the filter is not an option; and using the visible switch doesn’t leave data accessible for javascript.
Thought about using javascript to hide on page load, but that seems real messy, and might not look fantastic in all browsers.
It does not hide the correspondent cell in the filter row, as shown in the attached picture of post #1, there is an additional green cell on the right. I have the same problem with #1, namely, I need something like
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:
One slight adjustment to meet the initial requirements of the question. This retains the hidden_field_name filter value by attaching it to the filter of the field_name column.
How about setting the style="width:0px;" as needed on the column? Not sure where to do that because it would depend on Why to hide the column (isGuest?, isPageTwo?, etc.)
If you want to pass data to your javascript and are filling the grid using a CSqlDataProvider, then you could take advantage of the way the CGridView handles the id’s.
In the sql for CSqlDataProvider there must be a field called ‘id’ for the grid to work. But this id can be anything. So to pass e.g. ‘statusfield’ to javascript, you could write something like:
(in a model)
public static function listMyItems() {
return new CSqlDataProvider(
"select concat(id, '_', statusfield) id, other, fields from myitems",
);
}
function dosomejavascript(gridid) {
var id=$.fn.yiiGridView.getSelection(gridid);
if (id.length==0) return; //user de-selected the row
var info = id[0].split('_');
console.log('original id', info[0]);
console.log('statusfield', info[1]);
}