when i was doing client side paging and changed the page size in the radgrid at runtime, it is throwing error at
var link = item.get_cell(“Project”).getElementsByTagName(“a”)[0]; as
Uncaught TypeError: Cannot set property ‘innerHTML’ of undefined.
I totally have 3 rows to be binded in the grid. If i set pagesize in the aspx as 10 and then change the pagesize at run time to 20 it works.
But if i set the pagesize in aspx as 1 and later change the pagesize in the runtime to 10 it’s not working.
ASPX:
<telerik:RadGrid ID="RadGrid1" Skin="Office2007" runat="server"
GridLines="None" AllowPaging="true" AllowSorting="true" AutoGenerateColumns="false" PageSize="1">
<ClientSettings>
<ClientEvents OnCommand="RadGrid1_Command" OnRowDataBound="OpenSurveys_OnRowDataBound" />
</ClientSettings>
<MasterTableView>
<Columns>
<telerik:GridBoundColumn DataField="ProjectID" HeaderText="ProjectID" Visible="False" />
<telerik:GridBoundColumn DataField="SurveyPriority" HeaderText ="Priority" DataType="System.String"/>
<telerik:GridHyperLinkColumn DataTextField="SurveyName" DataNavigateUrlFields="SurveyName"
UniqueName="Name" HeaderText="Name" ItemStyle-Font-Underline="true" />
<telerik:GridBoundColumn DataField="SurveyCompletionStatusForPanelist" HeaderText="Completion Status" DataType="System.String" />
<telerik:GridBoundColumn DataField="SurveyClosingDate" HeaderText="Due Date" DataFormatString="{0:d}"/>
<telerik:GridBoundColumn DataField="AdditionalInfo" HeaderText ="Additional Information" />
</Columns>
</MasterTableView>
<PagerStyle AlwaysVisible="true" />
</telerik:RadGrid>
CS:
function OpenSurveys_OnRowDataBound(sender, args)
{
console.log("hyperlink");
// manually set the hyperlink's title
var item = args.get_item();
var dataItem = args.get_dataItem();
var link = item.get_cell("Name").getElementsByTagName("a")[0];
console.log("item,dataItem,link",item,dataItem,link);
link.innerHTML = dataItem.SurveyName;
link.href = dataItem.SurveyURL;
}
function pageLoad(sender, args)
{
document.getElementById("<%=RadGrid1.ClientID%>").style.display="block";
document.getElementById("<%=RadGrid2.ClientID%>").style.display="none";
OpenSurveysTableView = $find("<%= RadGrid1.ClientID %>").get_masterTableView();
$find("<%= RadAjaxLoadingPanel1.ClientID %>").show("<%= RadGrid1.ClientID %>");
commandName = "Load";
executeMethod("/WebServices/SurveyDetails.asmx", "OpenSurveys", getOpenSurveysRequestData(OpenSurveysTableView), updateOpenSurveyGrid, updateFailed);
}
function RadGrid1_Command(sender, args)
{
console.log("RadGrid1_Command");
args.set_cancel(true);
commandName = args.get_commandName();
console.log("commandName",commandName);
$find("<%= RadAjaxLoadingPanel1.ClientID %>").show("<%= RadGrid1.ClientID %>");
executeMethod("/WebServices/SurveyDetails.asmx", "OpenSurveys", getOpenSurveysRequestData(OpenSurveysTableView), updateOpenSurveyGrid, updateFailed);
}
function updateOpenSurveyGrid(result)
{
//alert(result);
$find("<%= RadAjaxLoadingPanel1.ClientID %>").hide("<%= RadGrid1.ClientID %>");
console.log("updateOpenSurveyGrid", result);
OpenSurveysTableView.set_dataSource(result);
OpenSurveysTableView.dataBind();
if (commandName == "PageSize" || commandName == "Load" || commandName == "Page") {
console.log("paging");
executeMethod("/WebServices/SurveyDetails.asmx", "GetOpenSurveyCount", "{}", updateOpenSurveyVirtualItemCount);
}
}
function updateOpenSurveyVirtualItemCount(result)
{
OpenSurveysTableView.set_virtualItemCount(result);
}
function getOpenSurveysRequestData(OpenSurveysTableView)
{
console.log("getOpenSurveysRequestData", OpenSurveysTableView)
var openpageSize = OpenSurveysTableView.get_pageSize();
var opencurrentPageIndex = OpenSurveysTableView.get_currentPageIndex();
var openstartIndex = openpageSize * opencurrentPageIndex;
//console.log("openpageSize,opencurrentPageIndex,openstartIndex,OpenSurveysTableView.get_pageSize()",openpageSize,opencurrentPageIndex,openstartIndex,OpenSurveysTableView.get_pageSize())
return JSON.stringify({
"startIndex": openstartIndex,
"maximumRows": OpenSurveysTableView.get_pageSize(),
"sortExpression": '',
"filterExpression": ''
});
}
function executeMethod(location, methodName, methodArguments, onSuccess, onFail)
{
//console.log("executeMethod", location, methodName, methodArguments, onSuccess, onFail);
$.ajax({
type: "POST",
url: location + "/" + methodName,
data: methodArguments,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: onSuccess,
fail: onFail
});
}