Here is my datagrid part in jsp:
<title>Device</title>
<script type="text/javascript">
var dataGrid;
$(function() {
dataGrid = $('#dataGrid').datagrid({
url : '${ctx}' + '/drivers/dataGrids',
striped : true,
rownumbers : true,
pagination : true,
singleSelect : true,
idField : 'id',
sortName : 'driversstatus',
sortOrder : 'desc',
pageSize : 15,
pageList : [ 10, 20, 30, 40, 50, 100, 200, 300, 400, 500 ],
frozenColumns : [ [ {
width : '100',
title : 'id',
field : 'id',
sortable : true
}, {
width : '80',
title : 'Device Name',
field : 'driversname',
sortable : true
} , {
width : '80',
title : 'Device ip',
field : 'driversip',
sortable : true
}, {
width : '80',
title : 'Device type',
field : 'driverstype',
sortable : true,
}, {
width : '80',
title : 'Device Status',
field : 'driversstatus',
sortable : true,
formatter : function(value, row, index) {
switch (value) {
case 0:
return 'Online';
case 1:
return 'Offline';
}
}
} ,{
width : '80',
title : 'Add Time',
field : 'addtime',
sortable : true,
}
] ],
toolbar : '#toolbar'
});
});
And here is my datagrid code in controller class:
#RequestMapping("/dataGrids")
#ResponseBody
public Grid jsonList(Drivers eqimInfo, PageFilter ph) {
Grid grid = new Grid();
grid.setPage(ph.getPage());
grid.setRows(driversService.dataGrid(eqimInfo, ph));
grid.setTotal(driversService.Count(eqimInfo, ph));
return grid;
}
Grid.class contains private attributes including page, rows and rowsCount, and their getter and setter; Drivers.class is the data class.
I can confirm that the returned Grid instances contains every data retrieved from the database, but the strange thing is that every columns have their values shown except the "Device Name" column, which drives me crazy......
Any suggestions?
Problem solved. Turns out that the first letter of the field in mySQL should use lower cases, otherwise jsp would not recognize it.
Related
I have a grid store with something like this.
var gridStore = Ext.create('Ext.data.Store',{
proxy : {
type : 'ajax',
actionMethods : {
read : 'POST'
},
url : 'getECIAgentWrapperJobs.do',
reader : {
type : 'json',
rootProperty : 'rows',
totalProperty : 'results'
}
},
pageSize : 3,
autoLoad : {start: 0, limit: 3}
});
Clearly it makes an AJAX request to the url.
The JSON response that I am getting for this store looks something like this :
{
"results":2,
"rows":[
{
"pkTable1":1,
"name":"Rick",
"eciAgentJob":{
"pkTable2":11,
"name":"Play Local Ar",
},
}
],
"msg":null,
"success":true,
}
Now this is how my grid looks :
var mappedEciAgentJobsGrids = Ext.create('Ext.grid.Panel',{
store : gridStore,
columns : [
{
dataIndex : 'pkTable1',
header : 'Pk of table 1'
},
{
dataIndex : 'name',
header : 'Name'
},
{
dataIndex : 'eciAgentJob.pkTable2',
header : 'Pk of Table 2'
}
]
});
Now in my UI the first 2 columns(with dataIndex: pkTable2 and name respectively) load fine. But for the 3rd one it does not.
I know it is because I have used dataIndex as 'eciAgentJob.pkTable2'. But then what is that way to load data in columns when we get response like the way I got(where eciAgentJob is a object inside the original JSON).
Please help.
Edit : I dont want to use a renderer due to some other use case reasons.
Define a new field in your model and map with the required field. In convert function pick any value from the record.
Ext.define('User', {
extend: 'Ext.data.Model',
fields: [
{ name: 'name', type: 'string ' },
{
name: 'columnName',
convert: function (value, record) {
return "return what ever you want"
}
}
]
});
I have this JSON string
[
{
uri : '/someuri/one',
title : 'Title 1',
displayLocation : 'ACTION_MENU',
masterData : 'LOCATION',
iconClass : 'icon-class-1'
},
{
uri : '/someuri/two',
title : 'Title 2',
displayLocation : 'ACTION_MENU',
masterData : 'LOCATION',
iconClass : 'icon-class-2'
},
{
uri : '/someuri/three',
title : 'Title 3',
displayLocation : 'ACTION_MENU',
masterData : 'JOB',
iconClass : 'icon-class-3'
},
{
uri : '/someuri/four',
title : 'Title 4',
displayLocation : 'SUMMARY',
masterData : 'LOCATION',
iconClass : 'icon-class-4'
}
]
I am converting it to
[
{
iconClass : 'icon-class-1',
id : 'anythingUnique',
text : 'Title 1'
},
{
iconClass : 'icon-class-2',
id : 'anythingUnique',
text : 'Title 2'
}
]
using following code
function myCustomFilter(inputJSONStr) {
return _.each(inputJSONStr.filter(function(action){
return action.masterData === 'LOCATION' && action.displayLocation === 'ACTION_MENU';
}), function (action) {
return [{iconClass: action.iconClass, id: 'anythingUnique', text: action.title}];
});
But its returning me JSON string
[
{
uri : '/someuri/one',
title : 'Title 1',
displayLocation : 'ACTION_MENU',
masterData : 'LOCATION',
iconClass : 'icon-class-1'
},
{
uri : '/someuri/two',
title : 'Title 2',
displayLocation : 'ACTION_MENU',
masterData : 'LOCATION',
iconClass : 'icon-class-2'
}
]
Can anyone suggest what I am doing wrong?
You could use map to do this:
_(inputJSONStr).filter({masterData: 'LOCATION', displayLocation: 'ACTION_MENU'})
.map(function(a) {
return {iconClass: a.iconClass, id: 'anythingUnique', text: a.title};
}).value();
I've changed your filter a little, but you could do it your way if you wanted, and I've used a functional approach with chaining, but you could do it imperatively if that makes you more comfortable. Map effectively replaces an array element with the returned element.
I have to call the EnhancedGrid filter plugin from a function, but in EnhancedGrid the filter plugin has to be declare in order to work with filter.
grid = new EnhancedGrid({
id : 'grid',
store : yourStore,
structure : layout,
rowSelector : '20px',
plugins : {
search : true,
pagination : {
pageSizes : [ "50", "100"],
description : true,
sizeSwitch : true,
pageStepper : true,
gotoButton : true,
maxPageStep : 2,
position : "bottom"
},
filter : {
closeFilterbarButton : true,
ruleCount : 2
itemsName : "rows"
}
}
});
grid.placeAt("myGrid");
grid.startup();
}
});
How can I achieve this?
You can do it this way:
<div data-dojo-type="dijit.form.Button">
filter movies with the letter "T" at the beginn
<script type="dojo/method" data-dojo-event="onClick" data-dojo-args="evt">
// Filter the movies from the data store:
grid3.filter({Title: "T*"});
</script>
It's a snippet from a dojo Example : https://dojotoolkit.org/reference-guide/1.9/dojox/grid/example_Filtering_data.html
Regards
I have a div which holds a DOJO table. The problem is, when I resize the browser, the DOJO table is not re-sized. How do I re-size it?? This is my div
<div id="grid1" jsid="grid1" dojoType="dojox.grid.EnhancedGrid" query="{ name: '*' }"
data-dojo-props="plugins:{ pagination:{pageSizes: ['10', '25', '50', '100'],
description: true, sizeSwitch: true, pageStepper: true, gotoButton: true, position: 'bottom', maxPageStep: 7}}, rowsPerPage:10"
style="height: 300px; width: 930px;"></div>
</div>
This is the DOJO table.
dojo.require("dojox.grid.EnhancedGrid");
dojo.require("dojox.grid.enhanced.plugins.Pagination");
dojo.require("dojo.data.ItemFileWriteStore");
dojo.require("dojox.grid.enhanced.plugins.Filter");
dojo.require("dojox.data.QueryReadStore");
dojo.require("dojo.parser");
var gridLayout = [
{
name : "Capacity",
classes : "title",
field : "capacityKVA",
width : "90px"
}, {
name : "Date & Time",
classes : "title",
field : "date",
width : "140px"
}, {
name : 'Status',
classes : "title",
field : "statusMessage",
fields : [ 'statusMessage', 'statusMessageColor' ],
formatter : formatLink1,
width : "140px"
}];
a simple table contains - id, name, text.
I need to bring these data in the grid with the grouping by the field name.
In all the examples that I found (for example - paper) uses the variable already defined the data. And I need to get data from Store.
ExtJs 3
The code:
Ext.onReady(function() {
var store = new Ext.data.JsonStore({
url : 'get_from_db.php',
storeId : 'MyStore',
totalProperty : 'totalCount',
idProperty : 'id',
remoteSort : true,
fields : [
{name : 'id', type : 'int'},
{name : 'name', type : 'String'},
{name : 'text', type : 'String'}
]
});
store.load();
var TestReader = new Ext.data.JsonReader({
idProperty : 'id',
fields : [
{name : 'id', type : 'int'},
{name : 'name', type : 'String'},
{name : 'text', type : 'String'}
]
});
var TestStore = new Ext.data.GroupingStore({
reader : TestReader,
data : 'get_from_db.php',
sortInfo : {
field : 'id',
direction : 'ASC'
},
groupField : 'name'
});
var TaskGrid = new Ext.grid.GridPanel({
store : TestStore,
columns : [
{id : 'id', header : 'Id', dataIndex : 'id'},
{id : 'name', header : 'Name', dataIndex : 'name'},
{id : 'text', header : 'Text', dataIndex : 'text'}
],
view : new Ext.grid.GroupingView({
forceFit : true,
groupTextTpl : '{text} ({[values.rs.length]} {[values.rs.length > 1 ? "Items" : "Item"]})'
}),
frame : true,
width : 700,
height : 450,
collapsible : true,
animCollapse : false,
title : 'Grouping',
renderTo : document.body
});
});
As a result, output grid without a single error, the group is - but here's the column values - all zeros
post the code of 'get_from_db.php', if you can, please.
$connect = mysql_connect('localhost', 'root', ''); if ($connect) mysql_select_db('grid') or die('error with select table'); $select = mysql_query("select * from test"); while ($rec = mysql_fetch_array($select)) $rows[] = $rec; echo json_encode($rows);
You made mistake in returning JSON. Instead
$rows[] = $rec;
you need
$rows[] = array ("id"=>$rec['id'], "name"=>$rec['name'], "text"=>$rec['text']);
decided. code:
Ext.onReady(function() {
var TestStore = new Ext.data.GroupingStore({
url : 'http://extjs/get_from_db.php',
autoLoad : true,
remoteGroup : true,
groupField : 'name',
sortInfo : {
field : 'id',
direction : 'ASC'
},
reader : new Ext.data.JsonReader({
totalProperty : 'totalCount',
root : 'items',
idProperty : 'id',
fields: [
{name : 'id', type : 'int'},
{name : 'name', type : 'String'},
{name : 'text' ,type : 'String'}
]
})
});
var TaskGrid = new Ext.grid.GridPanel({
store : TestStore,
colModel : new Ext.grid.ColumnModel({
columns : [
{id : 'id', header : 'Id', dataIndex : 'id'},
{header : 'Name', dataIndex : 'name'},
{header : 'Text', dataIndex : 'text'}
],
defaults : {
sortable : true,
menuDisabled : false,
width : 20
}
}),
view : new Ext.grid.GroupingView({
startCollapsed : true,
forceFit : true,
groupTextTpl : '{text} ({[values.rs.length]} {[values.rs.length > 1 ? "Items" : "Item"]})'
}),
frame : true,
width : 700,
height : 450,
collapsible : true,
animCollapse : false,
title : 'Grouping',
renderTo : document.body
});
});
More details in this note