gpt4 book ai didi

javascript - 如何创建可重复使用的 ig-grid

转载 作者:太空宇宙 更新时间:2023-11-04 15:55:57 24 4
gpt4 key购买 nike

我搜索了一个示例,但未能找到。我的目标是通过传入不同的变量来重用 CreateGrid 方法。我的问题是我无法动态设置网格中的列。我不知道如何传递 columns 变量。如果有人知道请提交一个例子或指导我一个例子。任何帮助表示赞赏。

谢谢...

示例:

   $(document).ready(function () {      
var blnAuto = false;


var dogs = @Html.Raw(Json.Encode(Model.DogList));
var gridA = "#gridDog";
var dogColumns = '{ key: "Type", headerText: "Type", dataType: "string", width: "50%"},{ key: "Name", headerText: "Name", dataType: "string", width: "50%" }'

CreateGrid(dogs, gridA, blnAuto, dogColumns);

var cars = @Html.Raw(Json.Encode(Model.CarList));
var gridB = "#gridCar";
var carColumns = '{ key: "Make", headerText: "Make", dataType: "string", width: "34%"},{ key: "Model", headerText: "Model", dataType: "string", width: "33%" }, { key: "Year", headerText: "Year", dataType: "string", width: "33%"}'

CreateGrid(cars, gridB, blnAuto, carColumns)
})



function CreateGrid(data, grid, autoGen, columnVariable)
{
var bln = false;


$(grid).igGrid({
width: "100%",
dataSource: data,
dataSourceType: "json",
autoGenerateColumns: bln,
columns: [ columnVariable ],
features: [
{
name: "Sorting",
type: "local",
applySortedColumnCss: false,
sortedColumnTooltip: "",
unsortedColumnTooltip: ""
}
]
});
}
</script>

最佳答案

我很尴尬,因为我没有注意到列是一个数组。设置列,例如:

var carColumns =  [
{ key: "Make", headerText: "Make", dataType: "string", width: "34%" },
{ key: "Model", headerText: "Model", dataType: "string", width: "33%" },
{ key: "Year", headerText: "Year", dataType: "string", width: "33%"}
]

var dogColumns = [
{ key: "Type", headerText: "Type", dataType: "string", width: "50%" },
{ key: "Name", headerText: "Name", dataType: "string", width: "50%" }
]

希望它可以帮助那里的人。

关于javascript - 如何创建可重复使用的 ig-grid,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42705847/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com