更新时间:2023-12-04 10:31:04
这是另一个选项想出了这个过滤器,每毫秒毫秒不要不必要地运行;这基本上使用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>