我正在使用最新版本的Dojo(1.10.4)。
默认网格显示正常并按预期执行但我需要它在将查询放入输入字段并单击按钮时更改它的存储。结构应该与所有设置保持一致。我只想将网格更改为新商店中的信息。
HTML
<h1 align="center">Submissions</h1>
<input type="text" id="query" name="query"></input><button class="srButton" onclick="changeGrid();">Search</button>
<div id="allSubGrid" ></div>
JS
var newGridQuery;
var grid, dataStore;
changeGrid = function() {
require([
"dojox/grid/EnhancedGrid",
"dojox/grid/enhanced/plugins/Pagination",
"dojo/store/Memory",
"dojo/data/ObjectStore",
"dojo/request",
"dijit/registry",
"dojo/domReady!"
], function(EnhancedGrid, Pagination, Memory, ObjectStore, request){
var newGrid = registry.byId("allSubGrid");
newGridQuery = document.getElementById('query').value
alert("REACHED");
request.get("http://localhost:8080/webapp/resultsBeta/"+ newGridQuery +".json", {
handleAs: "json"
}).then(function(data){
dataStore = new ObjectStore({ objectStore:new Memory({ data: data.submissions }) });
newGrid.store.close();
newGrid.setStore(dataStore);
newGrid.render();
});
});
}
require([
"dojox/grid/EnhancedGrid",
"dojox/grid/enhanced/plugins/Pagination",
"dojo/store/Memory",
"dojo/data/ObjectStore",
"dojo/request",
"dojo/domReady!"
], function(EnhancedGrid, Pagination, Memory, ObjectStore, request){
request.get("http://localhost:8080/webapp/submissions.json", {
handleAs: "json"
}).then(function(data){
dataStore = new ObjectStore({ objectStore:new Memory({ data: data.submissions }) });
grid = new EnhancedGrid({
store: dataStore,
items:data.items,
autoHeight: true,
rowSelector: '20px',
structure: [
{ name: "Submission ID", field: "id", width: "7.5%" },
{ name: "Filename", field: "filename", width: "10%" },
{ name: "Submitted By", field: "username", width: "10%" },
{ name: "Time", field: "time", width: "10%" }
],
plugins: {
pagination: {
pageSizes: ["25", "50", "100", "All"],
sizeSwitch: true,
pageStepper: true,
gotoButton: true,
maxPageStep: 4,
position: "bottom"
}
}
}, "allSubGrid");
grid.startup(); // Start grid
grid.on("RowClick", function(evt) { // On row click do something
var idx = evt.rowIndex, rowData = grid.getItem(idx);
require(["dijit/registry", "dijit/layout/ContentPane"], function(registry, ContentPane) { // on row click open up a new submission tab based on ID
var tab = new ContentPane({
title: 'Sub: ' + rowData.id,
closable: true,
href: 'submissions/' + rowData.id + '/',
id: 'sub_' + rowData.id
});
var tabContainer = registry.byId('subPanel');
tabContainer.addChild(tab);
tabContainer.selectChild(tab);
});
}, true);
});
});