Yii Framework Forum: Gridview Getchecked - Yii Framework Forum

Jump to content

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

Gridview Getchecked Rate Topic: -----

#1 User is offline   alex-w 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 223
  • Joined: 25-November 10

Posted 05 October 2012 - 04:43 AM

When calling getChecked if "column_id" isn't specified default to searching the first column of the table.

getChecked: function (column_id) {
  var settings = gridSettings[this.attr('id')],
    keys = this.find('.keys span'),
    checked = [];

  var input = undefined !== column_id
    ? 'td input[name="' + (column_id.match(/.+\[\]$/) ? column_id : column_id + '[]') + '"]'
    : 'td:first-child input';

  this.find('.' + settings.tableClass).find('tbody tr ' + input).each(function(i) {
    if (this.checked) {
       checked.push(keys.eq(i).text());
    }
  });
  return checked;
}

0

#2 User is offline   Maurizio Domba Cerin 

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

Posted 05 October 2012 - 06:42 AM

It's an interesting idea, but it can have possible problems if users do not read source code so if someone would call this method without a parameter and his first column is not a checkbox column he would not get the result he intended.

Info1: you changed substring with match but this method is slower then substring - http://jsperf.com/substring-vs-match-2

Info2: you changed to find() instead of children(), note that find is searching all nodes while children is searching only the first level child nodes, so children() is used because any grid cell can in addition contain another TABLE
Find more about me.... btw. Do you know your WAN IP?
0

#3 User is offline   alex-w 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 223
  • Joined: 25-November 10

Posted 05 October 2012 - 07:11 AM

I didn't know about these functions until having a look at the JS, are they documented anywhere?
Couldn't see anything in the class references.

Updated to more closely follow original.

getChecked: function (column_id) {
  var settings = gridSettings[this.attr('id')],
    keys = this.find('.keys span'),
    checked = [];

  var nth = '', input = 'input';
  if (undefined !== column_id) {
    if (column_id.substring(column_id.length - 2) !== '[]') {
      column_id = column_id + '[]';
    }
    input += '[name="' + column_id + '"]';
  } else
    nth = ':first-child';

  this.find('.' + settings.tableClass).children('tbody').children('tr')
    .children('td' + nth).children(input).each(function (i) {
      if (this.checked) {
        checked.push(keys.eq(i).text());
      }
    });
                        
  return checked;
}

0

#4 User is offline   Maurizio Domba Cerin 

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

Posted 05 October 2012 - 07:15 AM

There is no special documentation for Yii JS methods... getChecked() is mentioned in the doucmentation for selectableRows - http://www.yiiframew...ableRows-detail

You don't need to update the function, that was not the point, I just wanted to explain to you why those where used :D

The point is (as I wrote before) if this change is needed at all. The developer needs to know his column ID, and if a column ID is not sent (the developer forgot to put it as a parameter) the return value could be wrong like first column checked instead of the desired one, or nothing if the first column is not a checkbox column.


Find more about me.... btw. Do you know your WAN IP?
0

#5 User is offline   alex-w 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 223
  • Joined: 25-November 10

Posted 05 October 2012 - 07:27 AM

I want to make the code as efficient as possible so felt the need to update :)

This was mainly for convenience, I have a CCheckBoxColumn column with no name used for bulk actions.

btw, The documentation references the depreciated function.
0

#6 User is offline   Maurizio Domba Cerin 

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

Posted 05 October 2012 - 07:35 AM

Yes I know for the documentation, there is already an issue on github for this - https://github.com/y...yii/issues/1441
Find more about me.... btw. Do you know your WAN IP?
0

#7 User is offline   Maurizio Domba Cerin 

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

Posted 19 October 2012 - 07:56 AM

GutHub issue: https://github.com/y...t/yii/pull/1585
Find more about me.... btw. Do you know your WAN IP?
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