I have a grid with master and detail table view. If I rebind master table on client side by setting args.set_cancel(true); in OnCommand client side event it only bind with master table and but dont bind with detail table although I explicitly rebind each detail table after rebind master table but it does not work. If I rebind only each detail table it bind successfully.
addCompany2() called on button click.
var companies = null;
var empId = -1000;
var curDataItem = null;
var companyId = -100;
$(document).ready(pageLoad);
function pageLoad()
{
companies = [{"CompanyID":1,"CompanyName":"Moftak","Employees":[{"CompanyId":1,"FirstName":"Naeem","EmployeeID":1,"LastName":"Dad","Title":"","TitleId":0,"BirthDate":"","ShiftStart":"","JoinDate":""},{"CompanyId":1,"FirstName":"Nabil","EmployeeID":2,"LastName":"Manzoor","Title":"","TitleId":0,"BirthDate":"","ShiftStart":"","JoinDate":""}]},{"CompanyID":2,"CompanyName":"Chillisauce","Employees":[{"CompanyId":2,"FirstName":"James","EmployeeID":1,"LastName":"T","Title":"","TitleId":0,"BirthDate":"","ShiftStart":"","JoinDate":""},{"CompanyId":2,"FirstName":"Will","EmployeeID":2,"LastName":"Z","Title":"","TitleId":0,"BirthDate":"","ShiftStart":"","JoinDate":""}]},{"CompanyID":3,"CompanyName":"Microsoft","Employees":[{"CompanyId":3,"FirstName":"Niclus","EmployeeID":1,"LastName":"Gage","Title":"","TitleId":0,"BirthDate":"","ShiftStart":"","JoinDate":""},{"CompanyId":3,"FirstName":"Peter","EmployeeID":2,"LastName":"Khan","Title":"","TitleId":0,"BirthDate":"","ShiftStart":"","JoinDate":""}]}];
if(companies == null)
companies = new Array();
}
var bindIndex = 0;
function addCompany2()
{
debugger;
var company = new Object();
company.CompanyName = "Test Company";
company.CompanyID = companies.length+1;
companies[companies.length] = company;
var grd = $find("<%= RadGrid1.ClientID %>");
document.getElementById("hdCompanies").value = $.toJSON(companies);
grd.get_masterTableView().rebind();
for(var i=0;i<companies.length;i++)
{
if(grd.get_detailTables()[i] != null)
{
grd.get_detailTables()[i].rebind();
bindIndex++;
}
}
bindIndex = 0;
}
function OnCommand(sender,args)
{
args.set_cancel(true);
if(args.get_commandName() == "RebindGrid")
{
resetContainers();
if(args.get_tableView().get_name() == "Company")
{
sender.get_masterTableView().set_dataSource(companies);
sender.get_masterTableView().dataBind();
}
if(args.get_tableView().get_name() == "Employee")
{
sender.get_detailTables()[bindIndex].set_dataSource(companies[bindIndex].Employees);
sender.get_detailTables()[bindIndex].dataBind();
}
}
}
addCompany2() called on button click.
var companies = null;
var empId = -1000;
var curDataItem = null;
var companyId = -100;
$(document).ready(pageLoad);
function pageLoad()
{
companies = [{"CompanyID":1,"CompanyName":"Moftak","Employees":[{"CompanyId":1,"FirstName":"Naeem","EmployeeID":1,"LastName":"Dad","Title":"","TitleId":0,"BirthDate":"","ShiftStart":"","JoinDate":""},{"CompanyId":1,"FirstName":"Nabil","EmployeeID":2,"LastName":"Manzoor","Title":"","TitleId":0,"BirthDate":"","ShiftStart":"","JoinDate":""}]},{"CompanyID":2,"CompanyName":"Chillisauce","Employees":[{"CompanyId":2,"FirstName":"James","EmployeeID":1,"LastName":"T","Title":"","TitleId":0,"BirthDate":"","ShiftStart":"","JoinDate":""},{"CompanyId":2,"FirstName":"Will","EmployeeID":2,"LastName":"Z","Title":"","TitleId":0,"BirthDate":"","ShiftStart":"","JoinDate":""}]},{"CompanyID":3,"CompanyName":"Microsoft","Employees":[{"CompanyId":3,"FirstName":"Niclus","EmployeeID":1,"LastName":"Gage","Title":"","TitleId":0,"BirthDate":"","ShiftStart":"","JoinDate":""},{"CompanyId":3,"FirstName":"Peter","EmployeeID":2,"LastName":"Khan","Title":"","TitleId":0,"BirthDate":"","ShiftStart":"","JoinDate":""}]}];
if(companies == null)
companies = new Array();
}
var bindIndex = 0;
function addCompany2()
{
debugger;
var company = new Object();
company.CompanyName = "Test Company";
company.CompanyID = companies.length+1;
companies[companies.length] = company;
var grd = $find("<%= RadGrid1.ClientID %>");
document.getElementById("hdCompanies").value = $.toJSON(companies);
grd.get_masterTableView().rebind();
for(var i=0;i<companies.length;i++)
{
if(grd.get_detailTables()[i] != null)
{
grd.get_detailTables()[i].rebind();
bindIndex++;
}
}
bindIndex = 0;
}
function OnCommand(sender,args)
{
args.set_cancel(true);
if(args.get_commandName() == "RebindGrid")
{
resetContainers();
if(args.get_tableView().get_name() == "Company")
{
sender.get_masterTableView().set_dataSource(companies);
sender.get_masterTableView().dataBind();
}
if(args.get_tableView().get_name() == "Employee")
{
sender.get_detailTables()[bindIndex].set_dataSource(companies[bindIndex].Employees);
sender.get_detailTables()[bindIndex].dataBind();
}
}
}