Html table plugin |
[eluser]xwero[/eluser]
Yesterday my attention was drawn to the html table class and because it got stuck in my head i created the html table plugin. It does everything the html table class does except for adding a database object as table content. The benefits are : - no markup in the controller - more in control of the output - multiple header rows Code: <?php Code: function view_path($view) Code: /* break array up into multiple columns */ Enjoy! UPDATE 1 : If $header, $body or $footer are a single array it will be transformed to a two dimensional array UPDATE 2 : based on sophistry's response i removed the nested loop and replaced the not empty check with a count higher than 0 check.
[eluser]sophistry[/eluser]
hi xwero, thanks for that. here's a more readable way to get the "NBSP stuffed" columns. i'm a "library" coder so when i saw what you were doing in the while loop i thought "array_chunk, array_pad". also, is_num() function made my output into a blank page, so i changed it to is_numeric(). Code: function table($view_path,$body,$header= array(),$footer = array(),$columns=0)
[eluser]xwero[/eluser]
i stole the column part from the table class I already changed the is_num mistake.
[eluser]sophistry[/eluser]
hi xwero, any reason why you took out the array_pad() that inserts the Code: EDIT: oops, i realized that the array_pad() as shown above won't work. it needs to have an array_push() or a squarebrackets array push after the pop and pad. does that make sense? also, i rely on the "subscribe to this thread" option. But, if you update the original post the forum does not send an email. so, you made a bunch of changes and i just happened to look back onto this thread. otherwise i would never have seen that you made changes. just a heads up that when you edit posts it doesn't send out emails to thread subscribers. cheers.
[eluser]xwero[/eluser]
I took the array_pad out because why do you need to create cells for nothing? This works for the array_pad Code: $body[count($body)-1] = array_pad(end($body),$columns,' '); I will keep it in mind about the updates but i don't think there will be other changes. The function is feature complete and developer friendly. Only when people find bugs or suggest really neat additions the function will be updated.
[eluser]sophistry[/eluser]
of course there *is* a reason the NBSP stuffing code was in the CI class: browser rendering differences. this link has a little bit about it. also, border-rendering problems come up when you don't have the proper number of TD tags to match your defined header columns. best opt to create a complete table and maybe make the NBSP a more obvious option? it has to be something because otherwise your tables will render strangely. http://www.w3schools.com/html/html_tables.asp cheers.
[eluser]xwero[/eluser]
The link mentions empty cells not missing cells. I didn't find anything on rendering problems with missing cells. Of course if the css styles the cells left and/or right border you have to pad the row. But I rather give developers the choice if they want to pad the last row or not. What if they want to pad it with another content than NBSP?
[eluser]sophistry[/eluser]
use your own browser to test what happens when you don't emit a TD tag inside a table that is "expecting" one (i.e., no colspan attributes anywhere). what does your browser show? mine (safari 3 and 4, firefox) shows no border when there is no TD tag. so, it's unexpected behavior for a table rendering function to emit a table that has missing tags (regardless of what's in them). two things: 1) missing TD tag inside a table - my browsers show no border on the cell even if you use CSS. the developer/designer could try this CSS to make up for the lack of TD tags but it wouldn't work (not in firefox and not in safari) CSS cannot cure missing TD tags, but it does cure empty cells by giving them a border. Code: table { empty-cells:show; } 2) empty value inside TD tag - allow the developer to specify what to include in empty cells as an option. just put it in a class var like in the CI table class. cheers.
[eluser]xwero[/eluser]
You are right but I think the better question is when do you need to break up a single array to create a table? And do you show the cell borders in that situation? The only time i show cell borders is when the table content is database like. If the content are rows of user/friendly content i use zebra stripes and padding to make it easier on the eyes. And i think many people do the same. 5 parameters is enough for a function, i don't like functions with too many parameters if they have different content types. Following is an example on how you can add custom content to empty cells by adding a class Code: $columns = 4;
[eluser]sophistry[/eluser]
[quote author="xwero" date="1236952876"]You are right but I think the better question is when do you need to break up a single array to create a table? And do you show the cell borders in that situation? [/quote] yes, i agree. i never rely on that feature of the table class except in calendar generation. my other table usage scenario is database display which of course has equal column numbers in every row. sometimes it's easier to argue about tiny little distractions and opinions on syntax than it is to realize what you are arguing about! thanks for the code submission and nice discussion, xwero. |
Welcome Guest, Not a member yet? Register Sign In |