一组 datastore 方法的集合
注意,任务(Tasks)和链接(Links)应通过标准的 Gantt API 进行管理。直接在 datastore 中修改任务或链接可能会引发意外问题。datastore 主要用于资源或其他自定义对象的管理。
您可以使用 createDatastore 方法创建一个新的 datastore。
datastore 对象提供以下 方法 和 事件:
gantt.$resourcesStore.parse([
{id: 1, text: "QA", parent:null},
{id: 2, text: "Development", parent:null},
{id: 3, text: "Sales", parent:null},
{id: 4, text: "Other", parent:null},
{id: 5, text: "Unassigned", parent:4},
{id: 6, text: "John", parent:1},
{id: 7, text: "Mike", parent:2},
{id: 8, text: "Anna", parent:2},
{id: 9, text: "Bill", parent:3},
{id: 10, text: "Floe", parent:3}
]);
var store = gantt.getDatastore(gantt.config.resource_store);
var resource = store.getItem(resourceId);
var store = gantt.getDatastore(gantt.config.resource_store);
var resource = store.getItem(resourceId);
resource.text = "modified";
store.updateItem(resourceId);
// or
store.updateItem(resourceId, { text: "modified" });
var store = gantt.getDatastore(gantt.config.resource_store);
store.removeItem(resourceId);
var store = gantt.getDatastore(gantt.config.resource_store);
if(store.isVisible(resourceId)){
console.log(resourceId);
}
var store = gantt.getDatastore(gantt.config.resource_store);
var items = store.getVisibleItems();
var store = gantt.getDatastore(gantt.config.resource_store);
var itemId = store.addItem({
text: "Unassigned",
parent:4
});
var store = gantt.getDatastore(gantt.config.resource_store);
var itemId = store.addItem({
text: "Unassigned",
parent:4
});
// itemId 是新项目的临时客户端 id
// 保存到数据库后,更新客户端的 id:
store.changeId(itemId, "databaseId");
var store = gantt.getDatastore(gantt.config.resource_store);
if(store.exists(resourceId)){
console.log(resourceId);
}
var store = gantt.getDatastore(gantt.config.resource_store);
// 交换两个项目
var idA = 1;
var idB = 5;
var indexA = store.getIndexById(idA);
var indexB = store.getIndexById(idB);
store.move(indexB, indexA);
indexA = store.getIndexById(idA);
store.move(indexA, indexB);
var store = gantt.getDatastore(gantt.config.resource_store);
store.clearAll();
var store = gantt.getDatastore(gantt.config.resource_store);
store.silent(function(){
store.eachItem(function(item){
item.text += " modified";
store.updateItem(item.id);
});
});
store.refresh();
var store = gantt.getDatastore(gantt.config.resource_store);
store.refresh(itemId); // 重绘指定项目
store.refresh(); // 重绘所有项目
var store = gantt.getDatastore(gantt.config.resource_store);
store.attachEvent("onParse", function(){
alert(store.count() + " items loaded");
});
var store = gantt.getDatastore(gantt.config.resource_store);
alert(store.countVisible() + " items are visible");
var store = gantt.getDatastore(gantt.config.resource_store);
var searchItems = [];
store.eachItem(function(item){
if(!item.value){
searchItems.push(item);
}
});
var store = gantt.getDatastore(gantt.config.resource_store);
store.filter();
var store = gantt.getDatastore(gantt.config.resource_store);
store.parse([
{id: 1, text: "QA", parent:null},
{id: 2, text: "Development", parent:null},
{id: 3, text: "Sales", parent:null},
{id: 4, text: "Other", parent:null},
{id: 5, text: "Unassigned", parent:4},
{id: 6, text: "John", parent:1},
{id: 7, text: "Mike", parent:2},
{id: 8, text: "Anna", parent:2},
{id: 9, text: "Bill", parent:3},
{id: 10, text: "Floe", parent:3}
]);
// 切换列的排序方向
var resourceSortDirection = false;
function sortResources(){
resourceSortDirection = !resourceSortDirection;
gantt.getDatastore("resource").sort("text", resourceSortDirection)
gantt.render();
}
var resourceSortDirection = false;
function sortResources(){
resourceSortDirection = !resourceSortDirection;
gantt.getDatastore("resource").sort(function (resource1, resource2){
return resource1.id - resource2.id;
}, resourceSortDirection)
gantt.render();
}
var store = gantt.getDatastore(gantt.config.resource_store);
var itemsInViewPort = store.getIndexRange(5, 10); // 第5到第10个项目
var store = gantt.getDatastore(gantt.config.resource_store);
var items = store.getItems();
var store = gantt.getDatastore(gantt.config.resource_store);
var firstItem = store.getIdByIndex(0);
var store = gantt.getDatastore(gantt.config.resource_store);
var itemIndex = store.getIndexById(5);
var store = gantt.getDatastore(gantt.config.resource_store);
var firstId = store.getFirst();
var store = gantt.getDatastore(gantt.config.resource_store);
var lastId = store.getLast();
var store = gantt.getDatastore(gantt.config.resource_store);
var firstId = store.getFirst();
var secondId = store.getNext(firstId);
var store = gantt.getDatastore(gantt.config.resource_store);
var prevId = store.getPrev(itemId);
var store = gantt.getDatastore(gantt.config.resource_store);
store.destructor();
var store = gantt.getDatastore(gantt.config.resource_store);
store.attachEvent("onAfterSelect", function(id){
gantt.refreshData();
});
var store = gantt.getDatastore(gantt.config.resource_store);
store.callEvent("CustomEvent", [param1, param2]);
var store = gantt.getDatastore(gantt.config.resource_store);
var handlerId = store.attachEvent("onAfterSelect", function(id){
gantt.refreshData();
});
// 移除事件处理器
store.detachEvent(handlerId);
var store = gantt.getDatastore(gantt.config.resource_store);
store.attachEvent("onItemLoading", function(item){
if(item.valid){ // 根据自定义属性在加载时过滤项目
return true;
}
return false;
});
var store = gantt.getDatastore(gantt.config.resource_store);
store.attachEvent("onBeforeParse", function(item){
console.time("StoreParse");
});
store.attachEvent("onParse", function(item){
console.timeEnd("StoreParse");
});
var store = gantt.getDatastore(gantt.config.resource_store);
store.attachEvent("onBeforeParse", function(item){
console.time("StoreParse");
});
store.attachEvent("onParse", function(item){
console.timeEnd("StoreParse");
});
var store = gantt.getDatastore(gantt.config.resource_store);
store.attachEvent("onBeforeUpdate", function(id, item){
// 你的代码
return true;
});
var store = gantt.getDatastore(gantt.config.resource_store);
store.attachEvent("onAfterUpdate", function(id, item){
// 你的代码
});
var store = gantt.getDatastore(gantt.config.resource_store);
store.attachEvent("onBeforeDelete", function(id, item){
// 你的代码
return true;
});
var store = gantt.getDatastore(gantt.config.resource_store);
store.attachEvent("onAfterDelete", function(id, item){
// 你的代码
});
var store = gantt.getDatastore(gantt.config.resource_store);
store.attachEvent("onBeforeAdd", function(id, item){
// 你的代码
return true;
});
var store = gantt.getDatastore(gantt.config.resource_store);
store.attachEvent("onAfterAdd", function(id, item){
// 你的代码
});
var store = gantt.getDatastore(gantt.config.resource_store);
store.attachEvent("onIdChange", function(oldId, newId){
// 你的代码
});
var store = gantt.getDatastore(gantt.config.resource_store);
store.attachEvent("onClearAll", function(){
// 你的代码
});
var store = gantt.getDatastore(gantt.config.resource_store);
store.attachEvent("onBeforeStoreUpdate", function(id, item, action){
// 你的代码
return true;
});
var store = gantt.getDatastore(gantt.config.resource_store);
store.attachEvent("onStoreUpdated", function(id, item, action){
// 你的代码
});
var store = gantt.getDatastore(gantt.config.resource_store);
store.attachEvent("onBeforeFilter", function(){
console.time("filtering");
});
store.attachEvent("onFilter", function(){
console.timeEnd("filtering");
});
var store = gantt.getDatastore(gantt.config.resource_store);
store.attachEvent("onBeforeFilter", function(){
console.time("filtering");
});
store.attachEvent("onFilter", function(){
console.timeEnd("filtering");
});
var store = gantt.getDatastore(gantt.config.resource_store);
store.attachEvent("onFilterItem", function(id, item){
// 你的代码
return true;
});
var datastore = gantt.createDatastore({
name: gantt.config.resource_store,
type: "treeDatastore",
initItem: function (item) {
item.parent = item.parent || gantt.config.root_id;
item[gantt.config.resource_property] = item.parent;
item.open = true;
return item;
}
});
datastore.attachEvent("onDestroy", function(){
alert("free custom resources");
});
datastore.destructor();