Dojo setQuery()在DataGrid上 - 所有项目都消失? [英] Dojo setQuery() on DataGrid - all items disappear?

查看:109
本文介绍了Dojo setQuery()在DataGrid上 - 所有项目都消失?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经挣扎了我的大脑,做了大量的研究和测试,不知道发生了什么。



我有一个Dojo datagrid被声明静态地使用一些HTML。使用GUI,我的用户将添加项目到DataGrid,它应该是工作。但是,我想要使用一个使用Dojo的setQuery来过滤在DataGrid中显示的数据的某个功能。问题是,一旦我运行setQuery命令,网格中的所有数据就会消失,不管是否与查询匹配!



这里是一些示例代码:

  var layoutItems = [[
{
field:id,
name :ID,
width:'5px',
hidden:true
},
{
field:color,
name:颜色,
width:'80px'
}
]];

//创建一个空数据存储//
var storeData = {
identifier:'id',
label:'id',
items: []
}
var store3 = new dojo.data.ItemFileWriteStore({data:storeData});

...

 < div id =griddojoType =dojox.grid.DataGridjsId =grid5store =store3structure =layoutItemsqueryOptions ={deep:true}query = {}rowsPerPage =40>< / div> 

...

  function filterGrid(){
dijit.byId(grid)。setQuery({color:Red});
}

....

  function addItemToGrid(formdata){
var jsonobj = eval((+ dojo.toJson(formData,true)+));

var myNewItem = {
id:transactionItemID,
color:jsonobj.color
};
//将新项目插入商店:
store3.newItem(myNewItem);
store3.save({onComplete:savecomplete,onError:saveerror});
}


解决方案

这是另一个选项想出了这个过滤器,每毫秒毫秒不要不必要地运行;这基本上使用JavaScript来创建一个新的setInterval,它在500毫秒之后运行一次,然后执行一个clearInterval使它不再运行。看起来只是调用filterTheDataGrids()函数添加一个项目后不会做..我们必须延迟一秒钟,然后调用它:

  //在> OF B 
< script type =text / javascript>
//声明全局变量
var refreshDataGrid;
var refreshDataGridInterval = 500; //根据需要进行更改,以控制在添加或删除项目之后刷新数据网格等待多久。
< / script>

  //在>中输入OF B 
< script type =text / javascript>
函数filterTheDataGrids(){
if(dijit.byId(grid)!= undefined){
dijit.byId(grid)。filter({color:Red );
}
clearInterval(refreshDataGrid); //运行过滤器只需一次即可;如果过滤器运行得太快,则使全局refreshDataGridInterval变量变大
}
< / script>

  //在>中输入OF B 
< script type =text / javascript>
//设置数据的布局//
var layoutItems = [[
{
field:id,
name:ID,
width:'5px',
hidden:true
},
{
field:color,
name:Color,
width:'80px'
}
]];

//创建一个空数据存储//
var storeData = {
identifier:'id',
label:'id',
items: []
}
var store3 = new dojo.data.ItemFileWriteStore({data:storeData});
< / script>

  //将其输入到< HTML>的页面
< div id =griddojoType =dojox.grid.DataGridjsId =grid5store =store3structure =layoutItemsquery ={type:'*'} clientSort =truerowsPerPage =40>< / div>

 < script type =text / javascript> 
函数addItemToGrid(formdata){
//这个函数是通过对话框调用的,并且通过数据通过它//
var jsonobj = eval((+ dojo.toJson formData,true)+));

var myNewItem = {
id:transactionItemID,
color:jsonobj.color
};
//将新项目插入商店:
store3.newItem(myNewItem);
store3.save({onComplete:savecomplete,onError:saveerror});

//在filterTheDataGrids函数上创建setInterval;因为简单的调用函数就不行了;似乎称它太快或者
refreshDataGrid = setInterval(function(){filterTheDataGrids();},refreshDataGridInterval);
}
< / script>


I've racked my brain and done tons of research and testing and can't figure out what is going on.

I have a Dojo datagrid which is declared statically with some HTML. Using the GUI, my users will add items to the DataGrid, which works as it should. However, I'd like to have a function that is called at a certain point that uses Dojo's setQuery to filter the data that shows in the DataGrid. The problem is that once I run the setQuery command, ALL of the data in the grid disappears, no matter if it matches the query or not!

Here is some sample code:

var layoutItems = [[
    {
        field: "id",
        name: "ID",
        width: '5px',
        hidden: true
    },
    {
        field: "color",
        name: "Color",
        width: '80px'
    }
]];

// Create an empty datastore //
var storeData = {
    identifier: 'id',
    label: 'id',
    items: []
}
var store3 = new dojo.data.ItemFileWriteStore( {data : storeData} );

...

<div id="grid" dojoType="dojox.grid.DataGrid" jsId="grid5" store="store3" structure="layoutItems" queryOptions="{deep:true}" query="{}" rowsPerPage="40"></div>

...

function filterGrid() {
    dijit.byId("grid").setQuery({color:"Red"});
}

....

function addItemToGrid(formdata) {
    var jsonobj = eval("(" + dojo.toJson(formData, true) + ")");

    var myNewItem = {
        id: transactionItemID,
        color: jsonobj.color
    };
    // Insert the new item into the store:
    store3.newItem(myNewItem);
    store3.save({onComplete: savecomplete, onError: saveerror});
}

解决方案

Here is another option that I came up with, so that the filter is not running unnecessarily every x milliseconds; this basically uses JavaScript to make a new setInterval which runs once after 500 milliseconds and then does a clearInterval so that it doesn't run again. Looks like just calling the filterTheDataGrids() function after adding an item won't do.. we have to delay for a split second and then call it:

// PUT THIS IN THE <HEAD> OF THE PAGE
<script type="text/javascript">
    // Declare the global variables
    var refreshDataGrid;
    var refreshDataGridInterval = 500;    // Change this as necessary to control how long to wait before refreshing the Data Grids after an item is added or removed.
</script>

.

// PUT THIS IN THE <HEAD> OF THE PAGE
<script type="text/javascript">
    function filterTheDataGrids() {
         if (dijit.byId("grid") != undefined) {
              dijit.byId("grid").filter({color: "Red"});
         }
         clearInterval (refreshDataGrid);    // Running the filter just once should be fine; if the filter runs too quickly, then make the global refreshDataGridInterval variable larger
    }
</script>

.

// PUT THIS IN THE <HEAD> OF THE PAGE
<script type="text/javascript">
    // SETUP THE LAYOUT FOR THE DATA //
    var layoutItems = [[
    {
        field: "id",
        name: "ID",
        width: '5px',
        hidden: true
    },
    {
        field: "color",
        name: "Color",
        width: '80px'
    }
]];

// Create an empty datastore //
var storeData = {
    identifier: 'id',
    label: 'id',
    items: []
}
var store3 = new dojo.data.ItemFileWriteStore( {data : storeData} );
</script>

.

 // PUT THIS IN THE <HTML> OF THE PAGE
<div id="grid" dojoType="dojox.grid.DataGrid" jsId="grid5" store="store3" structure="layoutItems" query="{ type: '*' }" clientSort="true" rowsPerPage="40"></div>

.

<script type="text/javascript">
function addItemToGrid(formdata) {
    // THIS FUNCTION IS CALLED BY A DIALOG BOX AND GETS FORM DATA PASSED TO IT //
    var jsonobj = eval("(" + dojo.toJson(formData, true) + ")");

    var myNewItem = {
        id: transactionItemID,
        color: jsonobj.color
    };
    // Insert the new item into the store:
    store3.newItem(myNewItem);
    store3.save({onComplete: savecomplete, onError: saveerror});

    // Create setInterval on the filterTheDataGrids function; since simple calling the function won't do; seems to call it too fast or something
    refreshDataGrid = setInterval(function() {  filterTheDataGrids();   }, refreshDataGridInterval);
}
</script>

这篇关于Dojo setQuery()在DataGrid上 - 所有项目都消失?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆