mdomba, on 25 July 2012 - 04:18 AM, said:
I don't see why would that be "not clean" it's not a hack or anything like that...
if you have a good solution to be implemented in the core you can suggest it... just don't come with the undelegate (off) before delegate (on) solution as this has already been extensively discussed and is not proper.
Ok, I have a solution, which works for me.
The idea was:
We bind events when the the current id is not present in the settings array. And in the event callbacks, we use the settings array instead of a local copy, because in this case we can overwrite grid settings in a future request.
I can't attache JS files ("Error You aren't permitted to upload this kind of file").
How can I share it?
Here's the diff (line numbers are from a large concatenated file).
# This patch file was generated by NetBeans IDE
# It uses platform neutral UTF-8 encoding and \n newlines.
--- Remotely Modified (Based On HEAD)
+++ Locally Modified (Based On LOCAL)
@@ -3304,7 +3304,8 @@
return this.each(function () {
var $grid = $(this),
id = $grid.attr('id'),
- inputSelector = '#' + id + ' .' + settings.filterClass + ' input, ' + '#' + id + ' .' + settings.filterClass + ' select';
+ inputSelector = '#' + id + ' .' + settings.filterClass + ' input, ' + '#' + id + ' .' + settings.filterClass + ' select',
+ initialized = gridSettings[id];
settings.tableClass = settings.tableClass.replace(/\s+/g, '.');
if (settings.updateSelector === undefined) {
@@ -3313,8 +3314,10 @@
gridSettings[id] = settings;
+ if(!initialized) {
+
if (settings.ajaxUpdate.length > 0) {
- $(document).on('click', settings.updateSelector, function () {
+ $(document).on('click', gridSettings[id].updateSelector, function () {
$('#' + id).yiiGridView('update', {url: $(this).attr('href')});
return false;
});
@@ -3322,15 +3325,15 @@
$(document).on('change', inputSelector, function () {
var data = $(inputSelector).serialize();
- if (settings.pageVar !== undefined) {
- data += '&' + settings.pageVar + '=1';
+ if (gridSettings[id].pageVar !== undefined) {
+ data += '&' + gridSettings[id].pageVar + '=1';
}
$('#' + id).yiiGridView('update', {data: data});
});
- if (settings.selectableRows > 0) {
+ if (gridSettings[id].selectableRows > 0) {
selectCheckedRows(this.id);
- $(document).on('click', '#' + id + ' .' + settings.tableClass + ' > tbody > tr', function (e) {
+ $(document).on('click', '#' + id + ' .' + gridSettings[id].tableClass + ' > tbody > tr', function (e) {
var $currentGrid, $row, isRowSelected, $checks,
$target = $(e.target);
@@ -3343,23 +3346,23 @@
$checks = $('input.select-on-check', $currentGrid);
isRowSelected = $row.toggleClass('selected').hasClass('selected');
- if (settings.selectableRows === 1) {
+ if (gridSettings[id].selectableRows === 1) {
$row.siblings().removeClass('selected');
$checks.prop('checked', false);
}
$('input.select-on-check', $row).prop('checked', isRowSelected);
$("input.select-on-check-all", $currentGrid).prop('checked', $checks.length === $checks.filter(':checked').length);
- if (settings.selectionChanged !== undefined) {
- settings.selectionChanged(id);
+ if (gridSettings[id].selectionChanged !== undefined) {
+ gridSettings[id].selectionChanged(id);
}
});
- if (settings.selectableRows > 1) {
+ if (gridSettings[id].selectableRows > 1) {
$(document).on('click', '#' + id + ' .select-on-check-all', function () {
var $currentGrid = $('#' + id),
$checks = $('input.select-on-check', $currentGrid),
$checksAll = $('input.select-on-check-all', $currentGrid),
- $rows = $currentGrid.children('.' + settings.tableClass).children('tbody').children();
+ $rows = $currentGrid.children('.' + gridSettings[id].tableClass).children('tbody').children();
if (this.checked) {
$rows.addClass('selected');
$checks.prop('checked', true);
@@ -3369,14 +3372,15 @@
$checks.prop('checked', false);
$checksAll.prop('checked', false);
}
- if (settings.selectionChanged !== undefined) {
- settings.selectionChanged(id);
+ if (gridSettings[id].selectionChanged !== undefined) {
+ gridSettings[id].selectionChanged(id);
}
});
}
} else {
$(document).on('click', '#' + id + ' .select-on-check', false);
}
+ }
\ No newline at end of file
});
},