Yii Framework Forum: How to remove CgridView table class and add an id - Yii Framework Forum

Jump to content

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

How to remove CgridView table class and add an id Rate Topic: ***** 1 Votes

#1 User is offline   fouss 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 239
  • Joined: 05-October 10
  • Location:Bamako Mali

Posted 28 December 2010 - 10:11 AM

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">

Posted Image
0

#2 User is offline   fouss 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 239
  • Joined: 05-October 10
  • Location:Bamako Mali

Posted 28 December 2010 - 11:58 AM

View Postfouss, on 28 December 2010 - 10:11 AM, said:

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.
Posted Image
0

#3 User is online   mdomba 

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

Posted 28 December 2010 - 01:31 PM

As per current implementation you cannot without extending the CGridView...

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

#4 User is offline   fouss 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 239
  • Joined: 05-October 10
  • Location:Bamako Mali

Posted 29 December 2010 - 04:06 AM

View Postmdomba, on 28 December 2010 - 01:31 PM, said:

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
Posted Image
0

#5 User is offline   bogdev 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 07-December 11

Posted 09 February 2012 - 07:45 PM

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
0

#6 User is online   mdomba 

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

Posted 10 February 2012 - 04:13 AM

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

#7 User is offline   bogdev 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 07-December 11

Posted 02 March 2012 - 03:05 PM

View Postmdomba, on 10 February 2012 - 04:13 AM, said:

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.
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