Right justify numeric fields in table display - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Right justify numeric fields in table display (/showthread.php?tid=2491) |
Right justify numeric fields in table display - El Forum - 08-08-2007 [eluser]andycorpes[/eluser] Hi Group, I'm using the HTML table helper to create a table from a databaswe result. I can't figure out how to make the numeric columns right justified. Is there anyway to do this using the table template? or have i got to add each cell individually and specify an id or class attribute for each cell? Andy Right justify numeric fields in table display - El Forum - 08-08-2007 [eluser]Michael Wales[/eluser] I wouldn't use the table helper honestly - I would just loop through each of the returned results, something like this: Code: <table> You could then easily apply an id or class to any of the columns and style them with CSS. Or - if you want to be really ghetto with it, you could use CSS selectors (which may not be supported in all browsers) and setup an adjacent sibling selector: Code: tr > td + td + td {text-align:right;} That would target and td, that follows a td, that follows a td, that is a child of a tr. Right justify numeric fields in table display - El Forum - 08-08-2007 [eluser]Phil Sturgeon[/eluser] Code: <table> Not the neatest solution, but works. Right justify numeric fields in table display - El Forum - 08-08-2007 [eluser]Derek Allard[/eluser] Yeah, the problem with the table class is that it is really only good for uniform results (ie: database results) and lacks the flexibility that you'd need for these types of issues. I've been wanting to re-write that lib for a bit now That said, would something like this work for you? Code: $this->load->library('table'); Right justify numeric fields in table display - El Forum - 08-08-2007 [eluser]Phil Sturgeon[/eluser] Combine my ternary statements with that code in your controller and thats a perfect solution. |