AshishJoshi-asj / zfdatagrid

Automatically exported from code.google.com/p/zfdatagrid
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

(idea) Be able to add CSS on cell or row themselves #195

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
What is the expected output? What do you see instead?

Add CSS on row or cell elements instead of their content would be convenient.

What version of the product are you using? On what operating system?
v0.6 alpha, under defora

Please provide any additional information below.

Original issue reported on code.google.com by tribal...@gmail.com on 26 Feb 2010 at 3:25

GoogleCodeExporter commented 9 years ago
Oups... I complete.

I think about a kind of :

$grid->addClassRowCondition('<columnName>', '<condition>', '<rowCssClass(es)>');
$grid->addClassCellCondition('<columnName>', '<condition>', 
'<cellCssClass(es)>');

// eg :
$grid->addClassRowCondition(
    'columnB',          // column 'columnB'
    '%value% != 3',     // if value is not equals to 3
    "changeMyFontColor"     // use CSS class "changeMyFontColor"
);

Original comment by tribal...@gmail.com on 26 Feb 2010 at 3:27

GoogleCodeExporter commented 9 years ago
Hi, again :)

Another great idea.

Will try to make it happen before 0.6

But now I have a lot of work to do, and documentation is not ready yet.

Best Regards,
Bento Vilas Boas

Original comment by pao.fre...@gmail.com on 26 Feb 2010 at 3:32

GoogleCodeExporter commented 9 years ago
Hi,

Done.

Multiple conditions accepted.

Example:
$grid->addClassCellCondition('Population',"{{Population}} > 200000","red");
$grid->addClassCellCondition('Population',"{{Population}} < 200000","green");

OR
$grid->setClassCellCondition('Population',"{{Population}} < 200000","green");

addClassRowCondition
setClassRowCondition

Using the set method will clean all previous conditions....

The condition will be put in a IF statement. So make sure to add the ' around 
the
field to be treated like a string and not a number and to avoid notices.... 
'{{Name}}'

Revision 692

Best Regards,
Bento Vilas Boas

Original comment by pao.fre...@gmail.com on 26 Feb 2010 at 4:35

GoogleCodeExporter commented 9 years ago
Nice and fast, thanks :)

Original comment by tribal...@gmail.com on 26 Feb 2010 at 5:16

GoogleCodeExporter commented 9 years ago

Original comment by pao.fre...@gmail.com on 26 Feb 2010 at 10:54

GoogleCodeExporter commented 9 years ago
Hi,

using eighter of 
->addClassCellCondition('phoneHome',"substr('{{phoneHome}}',0,5) == 
'38591'","red");
->setClassCellCondition('phoneHome',"substr('{{phoneHome}}',0,5) == 
'38591'","red");

produces the same <td class="alt  red  ">...</td>
Shouldn't the second one remove the 'alt' class, and be just 'class="red"'?

Should parameter $column be removed from definition of function
 function setClassRowCondition ($column, $condition, $class)?

Or does it have any meaning?

Original comment by vlatko.b...@gmail.com on 1 Mar 2010 at 8:39

GoogleCodeExporter commented 9 years ago
Hi,

I do not think it would be judicious to remove 'alt' class.
In the absolute it is not linked to this functionality.

But in the absolute it could be convenient to be able active or desactivate this
even/odd class, and even be able to specify its name (in a website whose 
template is
already defined, 'alt' can be a class already in use)

$column paramater does not seems to be useful in fact. At this moment I do not 
see
it's usefullness. If current second parameter can take different {{field}} so it
could be work whatever the column specified in first one.

Original comment by tribal...@gmail.com on 1 Mar 2010 at 9:48

GoogleCodeExporter commented 9 years ago
Hi,

If 'alt' class (or any other) is not removed, it is an 'add' functionality 
than, not
a 'set'. 

Maybe the function call could be
->setClassCellCondition('field',"'{{field}}' > 10","oddClass", "evenClass")

Original comment by vlatko.b...@gmail.com on 1 Mar 2010 at 12:38

GoogleCodeExporter commented 9 years ago
Hi,

Made some changes:

Param $column from setClassRowCondition removed.

->setClassCellCondition("'{{field}}' > 10","oddClass", "evenClass");
->setClassCellCondition('field',"'{{field}}' > 10","oddClass", "evenClass");

Now work like this, makes sense.

However, if you add another condition afterwards the evenclass may be 
overridden. 

New method:

$grid->setGridCssClasses('oddClass','evenClass');

class "alt" removed from template.

let me know...

Revision 768

Best Regards,
Bento Vilas Boas

Original comment by pao.fre...@gmail.com on 1 Mar 2010 at 3:09

GoogleCodeExporter commented 9 years ago
The fact of keeping 'alt' by using addClass* and removing it by using setClass* 
is a
good idea.

But the event/odd behaviour is more linked to webdesign than to the component 
itself.
I think it would be necessary to be able to disable it (without using 
setClass*()
almost if there is no class to be set instead (how to disabled it so ?)).

For the moment it is wholly managed in a template class. If it becomes a 
predefined
behaviour which is activable/desactivable or overridable via a setClass*() (if 
keep)
it should be manage in the component itself : if activated, the user-defined CSS
class name (eg. 'alt' or 'myownoddevencss', ...) is added to the eventual other 
row
classes before calling the template loopLoop() (in which there will be no "%2 
== 0"
anymore).

Regarding to the condition you submit, it imposes that one field owning an
incremented value (whatever filter, order, ..., in use) exists.
I think it would be less memory-consuming to offer this odd/event behaviour as a
predefined functionality which has no equivalence with a setClass(). 

In passing, the 'alt' class should be on a row, and not on a cell (in a
<set|add>ClassRowCondition so, no ?)

What do you think about ?
(I hope I'm clear)

Original comment by tribal...@gmail.com on 1 Mar 2010 at 3:15

GoogleCodeExporter commented 9 years ago
Hi,

1. Maybe setGridCssClasses should be changed to something like 
setRowAlternateClasses or (shorter) setRowAltClasses? Or similar?
It is applied to TR level? Or...

setGridCssClasses does seem like the class for the whole grid (TABLE level)

2. I assume there is a typo. First one should be setClassRowCondition in

->setClassCellCondition("'{{field}}' > 10","oddClass", "evenClass");
->setClassCellCondition('field',"'{{field}}' > 10","oddClass", "evenClass");

3. Considering the same class for odd and even. If evenClass is empty, would the
oddClass be applied to both, or should the same class be specified twice?

4. @Tribal: Would 'alt' be disabled in for example, (empty class)
->setClassCellCondition("'{{field}}' > 10", "", "");

5. I'm not sure if I understood correctly Tribal at the end of the comment, but 
I do
think that rowClass should be applied on a TR level.

Original comment by vlatko.b...@gmail.com on 1 Mar 2010 at 3:37

GoogleCodeExporter commented 9 years ago
Hi,

Vlakto:

1. Applied to a tr level (after last commit)
Method renamed to setRowAltClasses();

2. Yes, its a type.

3.You should specify twice the same. Because if the evenClass is empty, that 
maybe
something that I want...

@Tribal: At this moment 'alt' is the default value for the odd class. This can 
be
changed. If a class is defined in the template, it won't be overridden by this 
method.

Revision 776

Best Regards,
Bento Vilas Boas

Original comment by pao.fre...@gmail.com on 1 Mar 2010 at 3:52

GoogleCodeExporter commented 9 years ago

2. Yes, its a type.

2. Yes, its a typo.

:D

Original comment by pao.fre...@gmail.com on 1 Mar 2010 at 3:53

GoogleCodeExporter commented 9 years ago
I'm ok with all of this (and almost with the "typo/type" debate ;)).

At any rate I like it, thanks.

PS : 4. I finally think 'alt' has just to be managed via setRowAltClasses() and 
does
not be modified according to <set|add>Class<Cell|Row>Condition() use.

Original comment by tribal...@gmail.com on 1 Mar 2010 at 4:13

GoogleCodeExporter commented 9 years ago
I have try the classRowCondition and that looks like not working.
An eye on the code :
Bvb_Grid_Data.php (l.1418) :
if (isset($this->_classRowCondition[0]) && 
is_array($this->_classRowCondition[0]) )
An index 0 is searched, whereas my $this->_classRowCondition contains a string 
as key.
(eg.
array
  'my_field' => 
    array
      0 => 
        array
          'condition' => string '{{my_field}} == 1' (length=34)
          'class' => string 'invalidRowClass' (length=15)
)

Condition declared with $this->_grid->addClassRowCondition('my_field', 
"{{my_field}}
== 1", 'invalidRowClass');

Original comment by tribal...@gmail.com on 1 Mar 2010 at 5:56

GoogleCodeExporter commented 9 years ago
Hi,

try without the 'my_field' for field. Not needed for Row, just for Cell. And 
both odd
and even classes should be specified, even if they are the same (see comment 
12, 3.)

->addClassRowCondition(
  "{{my_field}}== 1", 
  'invalidOddRowClass', 
  'invalidEvenRowClass');

Is it working now?

Original comment by vlatko.b...@gmail.com on 1 Mar 2010 at 7:04

GoogleCodeExporter commented 9 years ago
Hi,

The Row condition does not take any field...
$grid->setClassRowCondition("'{{Population}}' > 20000","green",'orange');

The above code is working. And the addClassCellCondition() is also working.

Best Regards,
Bento Vilas Boas

Original comment by pao.fre...@gmail.com on 1 Mar 2010 at 10:22

GoogleCodeExporter commented 9 years ago
Hi,

function definition for 
  ->setClassCellCondition('field',"'{{field}}' > 10","oddClass", "evenClass");

does not accept 'else' (evenClass), so I'm getting warning on Data.php (1440) 
that
index 'else' is undefined.

Original comment by vlatko.b...@gmail.com on 2 Mar 2010 at 8:34

GoogleCodeExporter commented 9 years ago
Hi,

The same issue persists.

Now the $this->_classRowCondition looks like :

array
  '{{my_field}} == 1' => 
    array
      0 => 
        array
          'condition' => string 'invalidRowClassYes' (length=15)
          'class' => string 'invalidRowClassNo' (length=17)

Condition does not seems to be at the well place (should it not be in 
'condition' key ?)

Original comment by tribal...@gmail.com on 2 Mar 2010 at 8:43

GoogleCodeExporter commented 9 years ago
Oups !
That works, now.
Thanks

Original comment by tribal...@gmail.com on 2 Mar 2010 at 8:53

GoogleCodeExporter commented 9 years ago
Hi Vlatko,

My mistake.

Was looking into the addClassCellCondition() and not setClassCellCondition()

Fixed

Best Regards,
Bento Vilas Boas

Original comment by pao.fre...@gmail.com on 2 Mar 2010 at 11:02

GoogleCodeExporter commented 9 years ago

Original comment by bento.vi...@gmail.com on 3 Mar 2010 at 4:56

GoogleCodeExporter commented 9 years ago
Hello,

Are you planning extend this function and be able to have more than 1 condition?
In my case I have 4 options with one color each one.

Is just an idea, I don't know if that will be very complicated.

Thanks

Ivo

Original comment by ivomonte...@gmail.com on 10 Jan 2011 at 3:55

GoogleCodeExporter commented 9 years ago
Hi Ivo,

You can do that already.

Just add another condition.

addClassCellCondition ($column, $condition, $class, $else = '')

addClassRowCondition ($condition, $class, $else = '')

Best Regards,
Bento Vilas Boas

Original comment by bento.vi...@gmail.com on 10 Jan 2011 at 7:09

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Thanks, it's working now.

I was using setClassRowCondition function, my mistake.

However, is there some function to disable Conditions when we export?
I'm receiving this error when trying export to pdf, excel, etc.:

"Message: call to unknown function addClassRowCondition"

Best Regards,
Ivo

Original comment by ivomonte...@gmail.com on 11 Jan 2011 at 10:08

GoogleCodeExporter commented 9 years ago
Hi Ivo,

You can use the isExport method to check if user is exporting the result.

if(!$rgid->isExport())
{
  //Add my row conditions here...
}

Best Regards,
Bento Vilas Boas

Original comment by bento.vi...@gmail.com on 13 Jan 2011 at 2:43