CGridView selectableRows

How can we automatically set the selectableRows value to be the total number of rows returned in the dataset?

Why would you need that?

Note that if selectableRows is 2 (or more) it means "ANY number of rows can be selected", it does NOT mean only 2 rows can be selected.

Oh I see. I assumed the value of selectableRows was the actual number of rows that can be selected. I already set it to 2 but I was only testing with a dataset of 2 rows anyway (lol).

But what if you had a bespoke requirement where you actually only wanted users to select 2 or ‘n’ number of rows, how would you do that?

Perhaps selectableRows should take a value of ‘true’ which means “any number of rows”, and integer values would specify an actual number of rows?

Because it doesn’t really make sense if you can put 2 or 3 or anything over 2 and they all mean unlimited.

With the current implementation you cannot… and this need is very rare… so if happens that you need that option you would need to code it by extending the CGridView…

Fair enough.

I just found a slight ‘inconsistency’ with how ‘selectableRows’ works in CGridView when using CCheckBoxColumn and the ‘check all’ checkbox:

  1. ‘selectableRows’ in CGridView
  • if you tick the ‘check all’ checkbox, all checkboxes are ticked. If you then untick one of the checkboxes the ‘check all’ checkbox remains ticked.

  • If the ‘check all’ checkbox is not ticked and you manually tick all checkboxes, the ‘check all’ checkbox doesn’t get ticked.

  1. ‘selectableRows’ in CCheckBoxColumn - does the opposite of all the above.

Is this the expected behaviour? I think CGridView needs to work the same as CheckBoxColumn. I’m using version 1.1.6

1 - when you untick one of the checkboxes, the "check all" checkbox should be unticked too, same if you tick all checkboxes… the "check all" should get ticked…

2 - can you explain what you mean with "the opposite"

I can confirm that is not happening when I use ‘selectableRows’=>2 in CGridView config.

When I use ‘selectableRows’=>2 in CCheckBoxColumn config:

  • tick ‘check all’ checkbox -> untick one checkbox -> the ‘check all’ checkbox is unticked

  • tick all checkboxes -> the ‘check all’ checkbox is auto ticked

The above is the correct implementation, it should be the same behaviour for CGridView

You’re right… I missed that…

will fix it…


I fixed this problem… -…e/detail?r=2891

Found one more… if all checkboxes where checked initialy the "chek all" was not selected, that should be fixed now…

Please test this…

Thanks for your help

NOTE: don’t forget to clear the assets folder

Hi mdomba, thanks for the quick response.

I’ve just tested this - unfortunately it is only “half” fixed…

The “check all” checkbox is only updating when you click on the actual checkboxes. If you click on the row instead it doesn’t update the “check all” checkbox.

Right… I was testing just the checkboxes…

Now it should work -

and again don’t forget to empty the assets folder

and many thanks for testing this…

Cheers boss - works perfectly now! Thanks again.

I agree the selectableRows behavior is non-intuitive. What’s the difference between setting selectableRows = 2 and selectableRows = 3?