我正在尝试将数据重新绑定到rowexpanding事件上的ighierarchicalgrid,并且它会抛出错误,例如“Uncaught TypeError:无法读取未定义的属性'_expandendnoevents'”。当我将initialExpandDepth作为1时,数据绑定。如果我删除它就会抛出错误。
$(document).ready(function () {
$.ajax({
type: "GET",
url: '@Url.Action("DataStoreData", "DataStore")',
data: JSON.stringify(),
contentType: "application/json; charset=utf-8",
dataType: "json",
async: true,
processData: false,
cache: false,
success: function (result) {
treegriddata = result;
igGridLoading(treegriddata);
collapseAllRows($("#hierarchicalGrid"));
}
});
});
function collapseAllRows(rootGrid) {
var level = 1, children, id, ad;
ad = rootGrid.igHierarchicalGrid("option", "animationDuration");
rootGrid.igHierarchicalGrid("option", "animationDuration", 0);
$(rootGrid.igGrid("allRows")).each(function (index, element) {
rootGrid.igHierarchicalGrid("collapse", element);
});
id = setInterval(function () {
children = rootGrid.igHierarchicalGrid("allChildren").filter("table[data-level='" + level + "']");
if (children.length > 0) {
$(children).each(function (index, element) {
$($(element).igGrid("allRows")).each(function (index, element) {
if ($(element).find("td.ui-iggrid-expandcolumn").length > 0 && ($(element).attr("state") === undefined || $(element).attr("state") === "c")) {
rootGrid.igHierarchicalGrid("collapse", element);
}
});
});
level++;
} else {
clearInterval(id);
rootGrid.igHierarchicalGrid("option", "animationDuration", ad);
}
}, 1000);
}
function igGridLoading(data) {
$("#hierarchicalGrid").igHierarchicalGrid({
width: "100%",
autoGenerateColumns: false,
dataSource: data,
autoCommit: true,
primaryKey: "ProjectId",
dataSourceType: "json",
autoGenerateLayots: false,
initialExpandDepth: 1,
columns: [
{ headerText: "Project Id", key: "ProjectId", dataType: "number", width: "0%", hidden: true },
{ headerText: "Project Ref", key: "ProjectRef", dataType: "string", width: "15%" },
{ headerText: "Project Desc", key: "ProjectDesc", dataType: "string", width: "20%" }
],
childrenDataProperty: "Process",
autoGenerateLayouts: false,
columnLayouts: [
{
key: "Process",
autoCommit: true,
//responseDataKey: "results",
autoGenerateColumns: false,
autofitLastColumn: false,
primaryKey: "ProjProcId",
width: "100%",
columns: [
{ headerText: "Project Process Id", key: "ProjProcId", dataType: "number", width: "100px", hidden: true },
{ headerText: "Process Code", key: "ProcessCode", dataType: "string", width: "100px" },
{ headerText: "Process Name", key: "ProcessName", dataType: "string", width: "150px" }
],
features: [
{
name: "Paging",
pageSize: 10
},
{
name: "Selection",
mode: "row",
multipleSelection: true
},
{
name: "Sorting",
type: "local"
},
{
name: "Filtering",
type: "local"
}
],
childrenDataProperty: "Components",
autoGenerateLayouts: false,
columnLayouts: [
{
key: "Components",
autoCommit: true,
//responseDataKey: "results",
autoGenerateColumns: false,
autofitLastColumn: false,
primaryKey: "ProcCompId",
width: "100%",
columns: [
{ headerText: "Process Component Id", key: "ProcCompId", dataType: "number", width: "100px", hidden: true },
{ headerText: "Component Code", key: "ComponentCode", dataType: "string", width: "120px" },
{ headerText: "Component Desc", key: "ComponentDesc", dataType: "string", width: "150px" },
{ headerText: "Component Value", key: "ComponentValue", dataType: "string", width: "150px" }
],
features: [
{
name: "Paging",
pageSize: 10
},
{
name: "Selection",
mode: "row",
multipleSelection: true
},
{
name: "Sorting",
type: "local"
},
{
name: "Filtering",
type: "local"
}
]
}
]
}
],
rowExpanding: function (e, args) {
var grid = args.owner, expandedRows, i;
expandedRows = $(args.parentrow).closest('tbody').find('tr[state=e]');
for (i = 0; i < expandedRows.length; i++) {
grid.collapse(expandedRows[i]);
}
var childGrid = args.parentrow.next().find("table.ui-iggrid-table");
//args.owner.element.parents("tr[data-container='true']").prevObject[0].rows['2'].parentNode.hidden = true;
var id = $(childGrid).attr("id");
var rows = $('#' + id).igGrid("rows");
if (rows.length === 0) {
$(args.parentrow.find("span")[0]).hide();
$('#' + id).hide();
}
},
features: [
{
name: 'Selection',
mode: 'row',
multipleSelection: false,
activation: true
}
],
rowExpanded: function (e, args) {
alert(e + args);
}
});
$("#hierarchicalGrid").igHierarchicalGrid("dataBind");
$("#hierarchicalGrid").on("ighierarchicalgridrowexpanding", function (evt, ui) {
var message = "ighierarchicalgridrowexpanding";
alert(message);
index = ui.parentrow.attr("data-id");
loadChildGridData(index);
});
}
function loadChildGridData(index) {
$.ajax({
type: "GET",
url: '/DataStore/DataStoreProcessData?key=' + index,
data: JSON.stringify(),
contentType: "application/json; charset=utf-8",
dataType: "json",
async: true,
processData: false,
cache: false,
success: function (result) {
var comp = treegriddata[index - 1].Process[0].Components;
treegriddata[index - 1].Process = result;
for (var i = 0; i < treegriddata[index - 1].Process.length; i++) {
treegriddata[index - 1].Process[i].Components = comp;
}
//Initialize
$("#hierarchicalGrid").igHierarchicalGrid({
initialDataBindDepth: 1
});
igGridLoading(treegriddata);
}
});
}