How to remove CgridView table class and add an id

How to remove Cgridview table class and add an id?

In my page code I have




<table class="items">



but I want it with an id like this




<table id="items">



I’m asking this because I need this table id to use in a jquery code.

As per current implementation you cannot without extending the CGridView…

But you can always use the class insted of the id in the jQuery…

That’s what I did finaly and it work.

thx

Found this while looking - here’s a quick fix with JQuery (put in after the widget):

Remove class and add id:

<script>

$(‘table’).removeClass(‘items’);

$(‘table’).attr(‘id’,‘items’);

</script>

Replacing a class:

<script>

$("table").removeClass("items").addClass("table");

</script>

IDs must be unique, so if you have more than one table you can iterate over an index:

<script>

$(‘table’).each(function(index){$(this).attr(‘id’, ‘table’ + index);});

</script>

…which will give you IDs of ‘table1’, ‘table2’, etc.

Yii haw

Note that your fix will work only once… on any event like pagination or sorting or filtering you will again get the old classes…

Good point - perhaps the script could be updated to rerun on table updates? I used the above script to apply the Twitter Bootstap CSS classes, but then realized I was losing the classes on pagination. Quite annoying.