Hi Martin,
Thanks for the note. Indeed, this issue is observed and it is related to a bugfix in RadGrid. In version 4.6.2 RadGrid used to lose synchronization for the header checkbox in GridClientSelect column, that said it was possible to have the checkbox checked when not all of the items are selected. The fix actually produced the issue in this specific scenario.
In order to handle it, you will need to attach an event handler to the client-side click event of the header checkbox. Check if there is any item selected and set the checkbox to be checked, else uncheck it. You will also need to manually select the header checkbox in case all enabled checkboxes are checked. Here is the updated client-side code:
<script type="text/javascript"> |
var selecting; |
var grid; |
var checkBox; |
function pageLoad() |
{ |
checkBox = $get($get('<%= HiddenField1.ClientID %>').value) |
$addHandler(checkBox, "click", onclickHandler); |
grid = $find('<%=RadGrid1.ClientID %>') |
// access the grid items, so that they are created and we can use grid selected items count is calculated correctly, bug -- will be fixed in Q1 |
var tmp = grid.get_masterTableView().get_dataItems().length; |
if (parseInt($get('<%= HiddenField2.ClientID %>').value, 10) + grid.get_masterTableView().get_selectedItems().length == grid.get_masterTableView().get_dataItems().length) |
{ |
checkBox.checked = true; |
} |
} |
function onclickHandler() |
{ |
if (grid.get_masterTableView().get_selectedItems().length > 0) |
{ |
checkBox.checked = true; |
} |
else |
{ |
checkBox.checked = false; |
} |
} |
var selecting = true; |
|
function RowSelecting(sender, args) |
{ |
var id = args.get_id(); |
var inputCheckBox = $get(id).getElementsByTagName("input")[0]; |
if (!inputCheckBox || inputCheckBox.disabled) |
{ |
//cancel selection for disabled rows |
args.set_cancel(true); |
} |
// if no more unselected enabled rows left - check the header checkbox |
else if (parseInt($get('<%= HiddenField2.ClientID %>').value, 10) + grid.get_masterTableView().get_selectedItems().length + 1 == grid.get_masterTableView().get_dataItems().length) |
{ |
checkBox.checked = true; |
} |
} |
function RowDeselecting(sender, args) |
{ |
checkBox.checked = false; |
} |
|
</script> |
You will find the updated project attached to the initial message.
Best wishes,
Ves
the Telerik team