我正在与Telerik RadGrid合作,并且我需要通过分页,排序和扩展来保留所选项目。过滤。我找到了this示例并尝试了他们的示例并获得了混合结果。有时它可以在Chrome中运行,虽然非常有缺陷(有时一次只允许一次选择)。当我在IE中运行它时出现此错误
无法获取属性'get_element'对象的值为null或 未定义
这是我正在使用的代码:
<telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
<script type="text/javascript">
var selected = {};
function RadGrid_RowSelected(sender, args) {
var rfp = args.getDataKeyValue("RFPID");
if (!selected[rfp]) {
selected[rfp] = true;
}
}
function RadGrid_RowDeselected(sender, args) {
var rfp = args.getDataKeyValue("RFPID");
if (selected[rfp]) {
selected[rfp] = null;
}
}
function RadGrid_RowCreated(sender, args) {
var rfp = args.getDataKeyValue("RFPID");
if (selected[rfp]) {
args.get_gridDataItem().set_selected(true);
}
}
function RadGrid_GridCreated(sender, eventArgs) {
var masterTable = sender.get_masterTableView();
var selectColumn = masterTable.getColumnByUniqueName("SelectColumnID");
var headerCheckBox = $(selectColumn.get_element()).find("[type=checkbox]")[0];
if (headerCheckBox) {
headerCheckBox.checked = masterTable.get_selectedItems().length ==
masterTable.get_dataItems().length;
}
}
</script>
</telerik:RadScriptBlock>
和网格:
<telerik:RadGrid ID="RadGrid1" runat="server" AllowSorting="True" AllowPaging="True"
OnNeedDataSource="RadGrid1NeedDataSource" Width="100%" AllowMultiRowSelection="True" AllowFilteringByColumn="false">
<MasterTableView AllowMultiColumnSorting="true" PageSize="100"
DataKeyNames="RFPID, PropCode, Parent, PropName, Address"
AutoGenerateColumns="true" ClientDataKeyNames="RFPID">
<Columns>
<telerik:GridClientSelectColumn />
</Columns>
<PagerStyle AlwaysVisible="true" />
</MasterTableView>
<ClientSettings EnableRowHoverStyle="true">
<Scrolling AllowScroll="True" UseStaticHeaders="True" SaveScrollPosition="True"></Scrolling>
<Selecting AllowRowSelect="true" />
<ClientEvents OnRowCreated="RadGrid_RowCreated" OnRowSelected="RadGrid_RowSelected"
OnRowDeselected="RadGrid_RowDeselected" OnGridCreated="RadGrid_GridCreated" />
</ClientSettings>
</telerik:RadGrid>
此行发生IE错误:
var headerCheckBox = $(selectColumn.get_element())发现( “[类型=复选框]”)[0];
答案 0 :(得分:0)
你错过了Jquery包含。
<telerik:RadScriptManager ID="RadScriptManager2" runat="server">
<Scripts>
<asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
<asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />
<asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js" />
</Scripts>
</telerik:RadScriptManager>