开发者

using dojo's datagrid and itemfilewritestore, is is possible to access parent data when generating the grid?

I have the following JSON data:

{identifier: "name",
label: "name",
items: [ 
      {"name": "ETL Processing", "type":"task", "startTime":"03:00:00", "endTime":"","status":"Running","totalJobs":"0","completeJobs":"0",
       children:[{_reference:"SubTaskName1"},{_reference:"SubTaskName2"},{_reference:"SubTaskName3"}]},
      {"name": "SubTaskName1","type":"subtask","startTime":"value","endTime":"value","status":"Done","totalJobs":"10","completeJobs":"10",
       children: [{_reference:"jobName1"},{_reference:"jobName2"},{_reference:"jobName3"}]},
      {"name": "SubTaskName2","type":"subtask","startTime":"value","endTime":"value","status":"Running","totalJobs":"20","completeJobs":"7",
       children: [{_reference:"jobName4"},{_reference:"jobName5"},{_reference:"jobName6"}]},
      {"name": "SubTaskName3","type":"subtask","startTime":"value","endTime":"value","status":"Pending","totalJobs":"45","completeJobs":"0",
       children: [{_reference:"jobName8"},{_reference:"jobName7"}]},
      {"name": "jobName1","type":"job","startTime":"value","endTime":"value","status":"Done","cpu":"0","memory":"0","logFile":"path"},
      {"name": "jobName2","type":"job","startTime":"value","endTime":"value","status":"Done","cpu":"0","memory":"0","logFile":"path"},
      {"name": "jobName3","type":"job","startTime":"value","endTime":"value","status":"Done","cpu":"0","memory":"0","logFile":"path"},
      {"name": "jobName4","type":"job","startTime":"value","endTime":"value","status":"Running","cpu":"15","memory":"4","logFile":"path"},
      {"name": "jobName5","type":"job","startTime":"value","endTime":"value","status":"Running","cpu":"40","memory":"23","logFile":"path"},
      {"name": "jobName6","开发者_运维技巧type":"job","startTime":"value","endTime":"value","status":"Pending","cpu":"0","memory":"1","logFile":"path"},
      {"name": "jobName7","type":"job","startTime":"value","endTime":"value","status":"Pending","cpu":"0","memory":"1","logFile":"path"},
      {"name": "jobName8","type":"job","startTime":"value","endTime":"value","status":"Running","cpu":"12","memory":"4","logFile":"path"},
]}

This data is first fed into an itemfilewritestore and then is loaded into a datagrid for presentation back to the user:

this.taskGrid = new dojox.grid.DataGrid({query:{type:"job"},
                                 store: TM.getCurrentTask().getTaskStore(),
                                 //autoWidth:true,
                                 //autoHeight:true,
                                 sortInfo: 2, //Sort by the start time
                                 clientSort:true,
                                 loadingMessage:"Loading...",
                                 noDataMessage:"No Task Data Found",
                                 rowSelector:true,
                                 structure: jobGridLayout},
                                  document.createElement("div"));

The datagrid's layout just spits out all of the job data to the user. As part of the datagrid I also want to include the name of a job's subtask (it's parent in the JSON result).

Is it possible to reference back to the individual job's parent subtask name in either the query or the layout, or do I need to just include the Subtask name in the individual job data?


I use this.store._getNewFileContentString() in one of my apps to turn the store data back to json. Might be able to get what you're after from there. I'm not sure if this will help you or not though, as I can't test it right now.


I was working through this for some time and got the below observations.

1)we need the power of querying the store so we have to use dojo.store.Memory which is an implementation of dojo object store.

memoryStore = new dojo.store.Memory({
    data : [ 
      {"name": "ETL Processing", "type":"task", "startTime":"03:00:00", "endTime":"","status":"Running","totalJobs":"0","completeJobs":"0",
       children:[{_reference:"SubTaskName1"},{_reference:"SubTaskName2"},{_reference:"SubTaskName3"}]},
      {"name": "SubTaskName1","type":"subtask","startTime":"value","endTime":"value","status":"Done","totalJobs":"10","completeJobs":"10",
       children: [{_reference:"jobName1"},{_reference:"jobName2"},{_reference:"jobName3"}]},
      {"name": "SubTaskName2","type":"subtask","startTime":"value","endTime":"value","status":"Running","totalJobs":"20","completeJobs":"7",
       children: [{_reference:"jobName4"},{_reference:"jobName5"},{_reference:"jobName6"}]},
      {"name": "SubTaskName3","type":"subtask","startTime":"value","endTime":"value","status":"Pending","totalJobs":"45","completeJobs":"0",
       children: [{_reference:"jobName8"},{_reference:"jobName7"}]},
      {"name": "jobName1","type":"job","startTime":"value","endTime":"value","status":"Done","cpu":"0","memory":"0","logFile":"path"},
      {"name": "jobName2","type":"job","startTime":"value","endTime":"value","status":"Done","cpu":"0","memory":"0","logFile":"path"},
      {"name": "jobName3","type":"job","startTime":"value","endTime":"value","status":"Done","cpu":"0","memory":"0","logFile":"path"},
      {"name": "jobName4","type":"job","startTime":"value","endTime":"value","status":"Running","cpu":"15","memory":"4","logFile":"path"},
      {"name": "jobName5","type":"job","startTime":"value","endTime":"value","status":"Running","cpu":"40","memory":"23","logFile":"path"},
      {"name": "jobName6","type":"job","startTime":"value","endTime":"value","status":"Pending","cpu":"0","memory":"1","logFile":"path"},
      {"name": "jobName7","type":"job","startTime":"value","endTime":"value","status":"Pending","cpu":"0","memory":"1","logFile":"path"},
      {"name": "jobName8","type":"job","startTime":"value","endTime":"value","status":"Running","cpu":"12","memory":"4","logFile":"path"},
    ]
})

2)Find the list of all subTask like this

subtsk = memoryStore.query({
    "type":"subtask"
});

3)Define a cell or subRow in the Grid with the formatter like this

{
    field: 'subtask',
    name: 'Sub Task Name',
    width: '150px',
    formatter:function(a,b,c){
        var jobName = this.grid.store.getValue(this.grid.getItem(b),"name");
        var subTask = ""
        dojo.forEach(subtsk,function(a){
            dojo.forEach(a.children,function(b,c){
                if(b._reference == jobName){
                    if(!subTask)
                    subTask = a.name;                               
                    //console.log(a.name)
                }
            })
        })
        return  subTask;

    }

}

I displayed the subtask name as a new subRow. And also, i'm bit not sure whether this is more efficient way of doing this task. If there are any problem please make post. I was able to get the Sub task name successfully.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜