Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
7e5630b5
Commit
7e5630b5
authored
Aug 06, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
GridView WIP
parent
61c7ac9d
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
163 additions
and
172 deletions
+163
-172
yii.gridView.js
framework/yii/assets/yii.gridView.js
+78
-0
GridView.php
framework/yii/widgets/GridView.php
+20
-8
ListViewBase.php
framework/yii/widgets/ListViewBase.php
+0
-4
CheckboxColumn.php
framework/yii/widgets/grid/CheckboxColumn.php
+35
-151
Column.php
framework/yii/widgets/grid/Column.php
+4
-9
GridViewAsset.php
framework/yii/widgets/grid/GridViewAsset.php
+26
-0
No files found.
framework/yii/assets/yii.gridView.js
0 → 100644
View file @
7e5630b5
/**
* Yii GridView widget.
*
* This is the JavaScript widget used by the yii\grid\GridView widget.
*
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
(
function
(
$
)
{
$
.
fn
.
yiiGridView
=
function
(
method
)
{
if
(
methods
[
method
])
{
return
methods
[
method
].
apply
(
this
,
Array
.
prototype
.
slice
.
call
(
arguments
,
1
));
}
else
if
(
typeof
method
===
'object'
||
!
method
)
{
return
methods
.
init
.
apply
(
this
,
arguments
);
}
else
{
$
.
error
(
'Method '
+
method
+
' does not exist on jQuery.yiiGridView'
);
return
false
;
}
};
var
defaults
=
{
};
var
methods
=
{
init
:
function
(
options
)
{
return
this
.
each
(
function
()
{
var
$e
=
$
(
this
);
var
settings
=
$
.
extend
({},
defaults
,
options
||
{});
$e
.
data
(
'yiiGridView'
,
{
settings
:
settings
});
});
},
setSelectionColumn
:
function
(
options
)
{
var
$grid
=
$
(
this
);
var
data
=
$grid
.
data
(
'yiiGridView'
);
data
.
selectionColumn
=
options
.
name
;
if
(
!
options
.
multiple
)
{
return
;
}
$grid
.
on
(
'click.yiiGridView'
,
"input[name='"
+
options
.
checkAll
+
"']"
,
function
()
{
$grid
.
find
(
"input[name='"
+
options
.
name
+
"']:enabled"
).
prop
(
'checked'
,
this
.
checked
);
});
$grid
.
on
(
'click.yiiGridView'
,
"input[name='"
+
options
.
name
+
"']:enabled"
,
function
()
{
var
all
=
$grid
.
find
(
"input[name='"
+
options
.
name
+
"']"
).
length
==
$grid
.
find
(
"input[name='"
+
options
.
name
+
"']:checked"
).
length
;
$grid
.
find
(
"input[name='"
+
options
.
checkAll
+
"']"
).
prop
(
'checked'
,
all
);
});
},
getSelectedRows
:
function
()
{
var
$grid
=
$
(
this
);
var
data
=
$grid
.
data
(
'yiiGridView'
);
var
keys
=
[];
if
(
data
.
selectionColumn
)
{
$grid
.
find
(
"input[name='"
+
data
.
selectionColumn
+
"']:checked"
).
each
(
function
()
{
keys
.
push
(
$
(
this
).
parent
().
closest
(
'tr'
).
data
(
'key'
));
});
}
return
keys
;
},
destroy
:
function
()
{
return
this
.
each
(
function
()
{
$
(
window
).
unbind
(
'.yiiGridView'
);
$
(
this
).
removeData
(
'yiiGridView'
);
});
},
data
:
function
()
{
return
this
.
data
(
'yiiGridView'
);
}
};
})(
window
.
jQuery
);
framework/yii/widgets/GridView.php
View file @
7e5630b5
...
@@ -15,6 +15,7 @@ use yii\base\Widget;
...
@@ -15,6 +15,7 @@ use yii\base\Widget;
use
yii\db\ActiveRecord
;
use
yii\db\ActiveRecord
;
use
yii\helpers\Html
;
use
yii\helpers\Html
;
use
yii\widgets\grid\DataColumn
;
use
yii\widgets\grid\DataColumn
;
use
yii\widgets\grid\GridViewAsset
;
/**
/**
* @author Qiang Xue <qiang.xue@gmail.com>
* @author Qiang Xue <qiang.xue@gmail.com>
...
@@ -26,7 +27,7 @@ class GridView extends ListViewBase
...
@@ -26,7 +27,7 @@ class GridView extends ListViewBase
const
FILTER_POS_FOOTER
=
'footer'
;
const
FILTER_POS_FOOTER
=
'footer'
;
const
FILTER_POS_BODY
=
'body'
;
const
FILTER_POS_BODY
=
'body'
;
public
$dataColumnClass
=
'yii\widgets\grid\DataColumn'
;
public
$dataColumnClass
;
public
$caption
;
public
$caption
;
public
$captionOptions
=
array
();
public
$captionOptions
=
array
();
public
$tableOptions
=
array
(
'class'
=>
'table table-striped table-bordered'
);
public
$tableOptions
=
array
(
'class'
=>
'table table-striped table-bordered'
);
...
@@ -70,7 +71,7 @@ class GridView extends ListViewBase
...
@@ -70,7 +71,7 @@ class GridView extends ListViewBase
* - `{sorter}`: the sorter. See [[renderSorter()]].
* - `{sorter}`: the sorter. See [[renderSorter()]].
* - `{pager}`: the pager. See [[renderPager()]].
* - `{pager}`: the pager. See [[renderPager()]].
*/
*/
public
$layout
=
"
{
summary}\n{pager}{items
}\n{pager
}
"
;
public
$layout
=
"
{
items}\n{summary
}\n{pager
}
"
;
public
$emptyCell
=
' '
;
public
$emptyCell
=
' '
;
/**
/**
* @var \yii\base\Model the model instance that keeps the user-entered filter data. When this property is set,
* @var \yii\base\Model the model instance that keeps the user-entered filter data. When this property is set,
...
@@ -107,11 +108,26 @@ class GridView extends ListViewBase
...
@@ -107,11 +108,26 @@ class GridView extends ListViewBase
if
(
!
$this
->
formatter
instanceof
Formatter
)
{
if
(
!
$this
->
formatter
instanceof
Formatter
)
{
throw
new
InvalidConfigException
(
'The "formatter" property must be either a Format object or a configuration array.'
);
throw
new
InvalidConfigException
(
'The "formatter" property must be either a Format object or a configuration array.'
);
}
}
if
(
!
isset
(
$this
->
options
[
'id'
]))
{
$this
->
options
[
'id'
]
=
$this
->
getId
();
}
$this
->
initColumns
();
$this
->
initColumns
();
}
}
/**
/**
* Runs the widget.
*/
public
function
run
()
{
$id
=
$this
->
options
[
'id'
];
$view
=
$this
->
getView
();
GridViewAsset
::
register
(
$view
);
$view
->
registerJs
(
"jQuery('#
$id
').yiiGridView();"
);
parent
::
run
();
}
/**
* Renders the data models for the grid view.
* Renders the data models for the grid view.
*/
*/
public
function
renderItems
()
public
function
renderItems
()
...
@@ -272,13 +288,12 @@ class GridView extends ListViewBase
...
@@ -272,13 +288,12 @@ class GridView extends ListViewBase
if
(
empty
(
$this
->
columns
))
{
if
(
empty
(
$this
->
columns
))
{
$this
->
guessColumns
();
$this
->
guessColumns
();
}
}
$id
=
$this
->
getId
();
foreach
(
$this
->
columns
as
$i
=>
$column
)
{
foreach
(
$this
->
columns
as
$i
=>
$column
)
{
if
(
is_string
(
$column
))
{
if
(
is_string
(
$column
))
{
$column
=
$this
->
createDataColumn
(
$column
);
$column
=
$this
->
createDataColumn
(
$column
);
}
else
{
}
else
{
$column
=
Yii
::
createObject
(
array_merge
(
array
(
$column
=
Yii
::
createObject
(
array_merge
(
array
(
'class'
=>
$this
->
dataColumnClass
,
'class'
=>
$this
->
dataColumnClass
?:
DataColumn
::
className
()
,
'grid'
=>
$this
,
'grid'
=>
$this
,
),
$column
));
),
$column
));
}
}
...
@@ -286,9 +301,6 @@ class GridView extends ListViewBase
...
@@ -286,9 +301,6 @@ class GridView extends ListViewBase
unset
(
$this
->
columns
[
$i
]);
unset
(
$this
->
columns
[
$i
]);
continue
;
continue
;
}
}
if
(
$column
->
id
===
null
)
{
$column
->
id
=
$id
.
'_c'
.
$i
;
}
$this
->
columns
[
$i
]
=
$column
;
$this
->
columns
[
$i
]
=
$column
;
}
}
}
}
...
@@ -305,7 +317,7 @@ class GridView extends ListViewBase
...
@@ -305,7 +317,7 @@ class GridView extends ListViewBase
throw
new
InvalidConfigException
(
'The column must be specified in the format of "Attribute", "Attribute:Format" or "Attribute:Format:Header'
);
throw
new
InvalidConfigException
(
'The column must be specified in the format of "Attribute", "Attribute:Format" or "Attribute:Format:Header'
);
}
}
return
Yii
::
createObject
(
array
(
return
Yii
::
createObject
(
array
(
'class'
=>
$this
->
dataColumnClass
,
'class'
=>
$this
->
dataColumnClass
?:
DataColumn
::
className
()
,
'grid'
=>
$this
,
'grid'
=>
$this
,
'attribute'
=>
$matches
[
1
],
'attribute'
=>
$matches
[
1
],
'format'
=>
isset
(
$matches
[
3
])
?
$matches
[
3
]
:
'text'
,
'format'
=>
isset
(
$matches
[
3
])
?
$matches
[
3
]
:
'text'
,
...
...
framework/yii/widgets/ListViewBase.php
View file @
7e5630b5
...
@@ -135,10 +135,6 @@ abstract class ListViewBase extends Widget
...
@@ -135,10 +135,6 @@ abstract class ListViewBase extends Widget
$totalCount
=
$this
->
dataProvider
->
getTotalCount
();
$totalCount
=
$this
->
dataProvider
->
getTotalCount
();
$begin
=
$pagination
->
getPage
()
*
$pagination
->
pageSize
+
1
;
$begin
=
$pagination
->
getPage
()
*
$pagination
->
pageSize
+
1
;
$end
=
$begin
+
$count
-
1
;
$end
=
$begin
+
$count
-
1
;
if
(
$end
>
$totalCount
)
{
$end
=
$totalCount
;
$begin
=
$end
-
$count
+
1
;
}
$page
=
$pagination
->
getPage
()
+
1
;
$page
=
$pagination
->
getPage
()
+
1
;
$pageCount
=
$pagination
->
pageCount
;
$pageCount
=
$pagination
->
pageCount
;
if
((
$summaryContent
=
$this
->
summary
)
===
null
)
{
if
((
$summaryContent
=
$this
->
summary
)
===
null
)
{
...
...
framework/yii/widgets/grid/CheckboxColumn.php
View file @
7e5630b5
...
@@ -7,185 +7,69 @@
...
@@ -7,185 +7,69 @@
namespace
yii\widgets\grid
;
namespace
yii\widgets\grid
;
use
Closure
;
use
yii\base\InvalidConfigException
;
use
yii\helpers\Html
;
/**
/**
* @author Qiang Xue <qiang.xue@gmail.com>
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
* @since 2.0
*/
*/
class
CheckboxColumn
extends
Column
class
CheckboxColumn
extends
Column
{
{
public
$checked
;
public
$name
;
/**
public
$checkboxOptions
=
array
();
* @var string a PHP expression that will be evaluated for every data cell and whose result will
public
$multiple
=
true
;
* determine if checkbox for each data cell is disabled. In this expression, you can use the following variables:
* <ul>
* <li><code>$row</code> the row number (zero-based)</li>
* <li><code>$data</code> the data model for the row</li>
* <li><code>$this</code> the column object</li>
* </ul>
* The PHP expression will be evaluated using {@link evaluateExpression}.
*
* A PHP expression can be any PHP code that has a value. To learn more about what an expression is,
* please refer to the {@link http://www.php.net/manual/en/language.expressions.php php manual}.
*
* Note that expression result will overwrite value set with <code>checkBoxHtmlOptions['disabled']</code>.
* @since 1.1.13
*/
public
$disabled
;
/**
* @var array the HTML options for the data cell tags.
*/
public
$htmlOptions
=
array
(
'class'
=>
'checkbox-column'
);
/**
* @var array the HTML options for the header cell tag.
*/
public
$headerHtmlOptions
=
array
(
'class'
=>
'checkbox-column'
);
/**
* @var array the HTML options for the footer cell tag.
*/
public
$footerHtmlOptions
=
array
(
'class'
=>
'checkbox-column'
);
/**
* @var array the HTML options for the checkboxes.
*/
public
$checkBoxHtmlOptions
=
array
();
/**
* @var integer the number of rows that can be checked.
* Possible values:
* <ul>
* <li>0 - the state of the checkbox cannot be changed (read-only mode)</li>
* <li>1 - only one row can be checked. Checking a checkbox has nothing to do with selecting the row</li>
* <li>2 or more - multiple checkboxes can be checked. Checking a checkbox has nothing to do with selecting the row</li>
* <li>null - {@link CGridView::selectableRows} is used to control how many checkboxes can be checked.
* Checking a checkbox will also select the row.</li>
* </ul>
* You may also call the JavaScript function <code>$(gridID).yiiGridView('getChecked', columnID)</code>
* to retrieve the key values of the checked rows.
* @since 1.1.6
*/
public
$selectableRows
=
null
;
/**
* @var string the template to be used to control the layout of the header cell.
* The token "{item}" is recognized and it will be replaced with a "check all" checkbox.
* By default if in multiple checking mode, the header cell will display an additional checkbox,
* clicking on which will check or uncheck all of the checkboxes in the data cells.
* See {@link selectableRows} for more details.
* @since 1.1.11
*/
public
$headerTemplate
=
'{item}'
;
/**
* Initializes the column.
* This method registers necessary client script for the checkbox column.
*/
public
function
init
()
public
function
init
()
{
{
if
(
isset
(
$this
->
checkBoxHtmlOptions
[
'name'
]))
{
parent
::
init
();
$name
=
$this
->
checkBoxHtmlOptions
[
'name'
];
if
(
empty
(
$this
->
name
))
{
}
else
{
throw
new
InvalidConfigException
(
'The "name" property must be set.'
);
$name
=
$this
->
id
;
if
(
substr
(
$name
,
-
2
)
!==
'[]'
)
{
$name
.=
'[]'
;
}
$this
->
checkBoxHtmlOptions
[
'name'
]
=
$name
;
}
}
$name
=
strtr
(
$name
,
array
(
'['
=>
"
\\
["
,
']'
=>
"
\\
]"
));
if
(
substr
(
$this
->
name
,
-
2
)
!==
'[]'
)
{
$this
->
name
.=
'[]'
;
if
(
$this
->
selectableRows
===
null
)
{
if
(
isset
(
$this
->
checkBoxHtmlOptions
[
'class'
]))
{
$this
->
checkBoxHtmlOptions
[
'class'
]
.=
' select-on-check'
;
}
else
{
$this
->
checkBoxHtmlOptions
[
'class'
]
=
'select-on-check'
;
}
return
;
}
$cball
=
$cbcode
=
''
;
if
(
$this
->
selectableRows
==
0
)
{
//.. read only
$cbcode
=
"return false;"
;
}
elseif
(
$this
->
selectableRows
==
1
)
{
//.. only one can be checked, uncheck all other
$cbcode
=
"jQuery(
\"
input:not(#
\"
+this.id+
\"
)[name='
$name
']
\"
).prop('checked',false);"
;
}
elseif
(
strpos
(
$this
->
headerTemplate
,
'{item}'
)
!==
false
)
{
//.. process check/uncheck all
$cball
=
<<<CBALL
jQuery(document).on('click','#{$this->id}_all',function() {
var checked=this.checked;
jQuery("input[name='$name']:enabled").each(function() {this.checked=checked;});
});
CBALL;
$cbcode
=
"jQuery('#
{
$this
->
id
}
_all').prop('checked', jQuery(
\"
input[name='
$name
']
\"
).length==jQuery(
\"
input[name='
$name
']:checked
\"
).length);"
;
}
if
(
$cbcode
!==
''
)
{
$js
=
$cball
;
$js
.=
<<<EOD
jQuery(document).on('click', "input[name='$name']", function() {
$cbcode
});
EOD;
Yii
::
app
()
->
getClientScript
()
->
registerScript
(
__CLASS__
.
'#'
.
$this
->
id
,
$js
);
}
}
}
}
/**
/**
* Renders the header cell content.
* Renders the header cell content.
* This method will render a checkbox in the header when {@link selectableRows} is greater than 1
* The default implementation simply renders {@link header}.
* or in case {@link selectableRows} is null when {@link CGridView::selectableRows} is greater than 1.
* This method may be overridden to customize the rendering of the header cell.
* @return string the rendering result
*/
*/
protected
function
renderHeaderCellContent
()
protected
function
renderHeaderCellContent
()
{
{
if
(
trim
(
$this
->
headerTemplate
)
===
''
)
{
$name
=
rtrim
(
$this
->
name
,
'[]'
)
.
'_all'
;
echo
$this
->
grid
->
blankDisplay
;
$id
=
$this
->
grid
->
options
[
'id'
];
return
;
$options
=
json_encode
(
array
(
}
'name'
=>
$this
->
name
,
'multiple'
=>
$this
->
multiple
,
'checkAll'
=>
$name
,
));
$this
->
grid
->
getView
()
->
registerJs
(
"jQuery('#
$id
').yiiGridView('setSelectionColumn',
$options
);"
);
$item
=
''
;
if
(
$this
->
header
!==
null
||
!
$this
->
multiple
)
{
if
(
$this
->
selectableRows
===
null
&&
$this
->
grid
->
selectableRows
>
1
)
{
return
parent
::
renderHeaderCellContent
();
$item
=
CHtml
::
checkBox
(
$this
->
id
.
'_all'
,
false
,
array
(
'class'
=>
'select-on-check-all'
));
}
elseif
(
$this
->
selectableRows
>
1
)
{
$item
=
CHtml
::
checkBox
(
$this
->
id
.
'_all'
,
false
);
}
else
{
}
else
{
ob_start
();
return
Html
::
checkBox
(
$name
,
false
,
array
(
'class'
=>
'select-on-check-all'
));
parent
::
renderHeaderCellContent
();
$item
=
ob_get_clean
();
}
}
echo
strtr
(
$this
->
headerTemplate
,
array
(
'{item}'
=>
$item
,
));
}
}
/**
/**
* Renders the data cell content.
* Renders the data cell content.
*
This method renders a checkbox in the data cell.
*
@param mixed $model the data model
* @param integer $
row the row number (zero-based)
* @param integer $
index the zero-based index of the data model among the models array returned by [[dataProvider]].
* @
param mixed $data the data associated with the row
* @
return string the rendering result
*/
*/
protected
function
renderDataCellContent
(
$
row
,
$data
)
protected
function
renderDataCellContent
(
$
model
,
$index
)
{
{
if
(
$this
->
value
!==
null
)
{
if
(
$this
->
checkboxOptions
instanceof
Closure
)
{
$value
=
$this
->
evaluateExpression
(
$this
->
value
,
array
(
'data'
=>
$data
,
'row'
=>
$row
));
$options
=
call_user_func
(
$this
->
checkboxOptions
,
$model
,
$index
,
$this
);
}
elseif
(
$this
->
name
!==
null
)
{
$value
=
CHtml
::
value
(
$data
,
$this
->
name
);
}
else
{
}
else
{
$value
=
$this
->
grid
->
dataProvider
->
keys
[
$row
];
$options
=
$this
->
checkboxOptions
;
}
$checked
=
false
;
if
(
$this
->
checked
!==
null
)
{
$checked
=
$this
->
evaluateExpression
(
$this
->
checked
,
array
(
'data'
=>
$data
,
'row'
=>
$row
));
}
$options
=
$this
->
checkBoxHtmlOptions
;
if
(
$this
->
disabled
!==
null
)
{
$options
[
'disabled'
]
=
$this
->
evaluateExpression
(
$this
->
disabled
,
array
(
'data'
=>
$data
,
'row'
=>
$row
));
}
}
return
Html
::
checkbox
(
$this
->
name
,
!
empty
(
$options
[
'checked'
]),
$options
);
$name
=
$options
[
'name'
];
unset
(
$options
[
'name'
]);
$options
[
'value'
]
=
$value
;
$options
[
'id'
]
=
$this
->
id
.
'_'
.
$row
;
echo
CHtml
::
checkBox
(
$name
,
$checked
,
$options
);
}
}
}
}
framework/yii/widgets/grid/Column.php
View file @
7e5630b5
...
@@ -20,11 +20,6 @@ use yii\widgets\GridView;
...
@@ -20,11 +20,6 @@ use yii\widgets\GridView;
class
Column
extends
Object
class
Column
extends
Object
{
{
/**
/**
* @var string the ID of this column. This value should be unique among all grid view columns.
* If this is not set, it will be assigned one automatically.
*/
public
$id
;
/**
* @var GridView the grid view object that owns this column.
* @var GridView the grid view object that owns this column.
*/
*/
public
$grid
;
public
$grid
;
...
@@ -49,7 +44,7 @@ class Column extends Object
...
@@ -49,7 +44,7 @@ class Column extends Object
/**
/**
* @var array|\Closure
* @var array|\Closure
*/
*/
public
$
body
Options
=
array
();
public
$
content
Options
=
array
();
public
$footerOptions
=
array
();
public
$footerOptions
=
array
();
/**
/**
* @var array the HTML attributes for the filter cell tag.
* @var array the HTML attributes for the filter cell tag.
...
@@ -81,10 +76,10 @@ class Column extends Object
...
@@ -81,10 +76,10 @@ class Column extends Object
*/
*/
public
function
renderDataCell
(
$model
,
$index
)
public
function
renderDataCell
(
$model
,
$index
)
{
{
if
(
$this
->
body
Options
instanceof
Closure
)
{
if
(
$this
->
content
Options
instanceof
Closure
)
{
$options
=
call_user_func
(
$this
->
body
Options
,
$model
,
$index
,
$this
);
$options
=
call_user_func
(
$this
->
content
Options
,
$model
,
$index
,
$this
);
}
else
{
}
else
{
$options
=
$this
->
body
Options
;
$options
=
$this
->
content
Options
;
}
}
return
Html
::
tag
(
'td'
,
$this
->
renderDataCellContent
(
$model
,
$index
),
$options
);
return
Html
::
tag
(
'td'
,
$this
->
renderDataCellContent
(
$model
,
$index
),
$options
);
}
}
...
...
framework/yii/widgets/grid/GridViewAsset.php
0 → 100644
View file @
7e5630b5
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace
yii\widgets\grid
;
use
yii\web\AssetBundle
;
/**
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class
GridViewAsset
extends
AssetBundle
{
public
$sourcePath
=
'@yii/assets'
;
public
$js
=
array
(
'yii.gridView.js'
,
);
public
$depends
=
array
(
'yii\web\YiiAsset'
,
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment