datastore 메서드 모음
참고, Tasks와 Links는 표준 Gantt API를 통해 관리해야 합니다. datastore 내에서 직접적으로 tasks나 links를 변경하면 예기치 않은 문제가 발생할 수 있습니다. 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();