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.
I have a kendo grid, defined as such:
$("#auditGrid").kendoGrid({
height: 650,
width: 650,
sortable: true,
filterable: true,
resizable: true,
columns: [
{ field: "ChangeTypeDescription", title: "Change Type" },
{ field: "LevelDescription", title: "Level" },
{ field: "Site.ShortName", title: "Site", width: "100px", },
{ field: "TimeStampLocal", title: "Date", type: "date", format: "{0: yyyy-MM-dd HH:mm:ss}" }
]
});
However, the column labelled "Site" does not display anything, even when I know there should be something there. Setting the field as "Site" instead of "Site.ShortName" shows a value of [object Object], but whenever I try to display ShortName off of Site, it shows an empty column. All other columns display properly.
Does anyone have any insight as to why this is happening?
The datasource schema, in case you need to see it:
schema: {
model: {
fields: {
ChangeTypeDescription: { type: "string" },
LevelDescription: { type: "string" },
Site: { type: "string" },
TimeStampLocal: { type: "date" }
}
}
},
You needs to use the template functionality for achieving it, just change the column description of the field Site as follows
{ field: 'Site', title: 'Site', template: '#= Site.ShortName# '}
I am trying to read following json data into a jqgrid.
var myStr = { "version" : 2,
"query" : "java",
"location" : "suwanee, ga",
"dupefilter" : true,
"highlight" : true,
"radius" : 25,
"start" : 1,
"end" : 10,
"totalResults" : 826,
"pageNumber" : 0,
"results" : [
{
"jobtitle" : "Software Development Team Lead Job",
"company" : "GM",
"city" : "Roswell",
"state" : "GA",
"country" : "US",
"formattedLocation" : "Roswell, GA",
"source" : "General Motors",
"date" : "Tue, 24 Dec 2013 08:21:00 GMT",
"snippet" : "principles, techniques and best practices. - Demonstrated expert knowledge in <b>Java<\/b> and\/or .NET. - Demonstrated expert knowledge in building, debugging and... ",
"url" : "http:\/\/www.indeed.com\/viewjob?jk=778874434418454d&qd=TOIxqcl1xBNMbg2vKTNLcp5QUXHMUbDABF-wK7BxUqwiE8mPbZ2XU9t5kjdQrB6FlsFPgK13DhJYpBc84nTJQYrzCHZtERhjBNeGyZxL6jI&indpubnum=4675158811138546&atk=18cme6tj519rh3c6",
"onmousedown" : "indeed_clk(this, '1050');",
"latitude" : 34.021976,
"longitude" : -84.35714,
"jobkey" : "778874434418454d",
"sponsored" : false,
"expired" : false,
"formattedLocationFull" : "Roswell, GA",
"formattedRelativeTime" : "1 day ago"
}
,
{
"jobtitle" : "Software Systems Engineer (Java\/J2EE)",
"company" : "Universal Business Solutions",
"city" : "Alpharetta",
"state" : "GA",
"country" : "US",
"formattedLocation" : "Alpharetta, GA",
"source" : "Universal Business Solutions",
"date" : "Tue, 17 Dec 2013 18:37:25 GMT",
"snippet" : "years experience with <b>Java<\/b> & J2EE Must be motivated... environment. Experienced with <b>Java<\/b>, J2EE, Oracle, UNIX, SQL, Unix Shell script, <b>Java<\/b> Script, MVC Desired... ",
"url" : "http:\/\/www.indeed.com\/viewjob?jk=7066b95f71004292&qd=TOIxqcl1xBNMbg2vKTNLcp5QUXHMUbDABF-wK7BxUqwiE8mPbZ2XU9t5kjdQrB6FlsFPgK13DhJYpBc84nTJQYrzCHZtERhjBNeGyZxL6jI&indpubnum=4675158811138546&atk=18cme6tj519rh3c6",
"onmousedown" : "indeed_clk(this, '1050');",
"latitude" : 34.074177,
"longitude" : -84.29121,
"jobkey" : "7066b95f71004292",
"sponsored" : false,
"expired" : false,
"formattedLocationFull" : "Alpharetta, GA",
"formattedRelativeTime" : "8 days ago"
}
,
{
"jobtitle" : "Software Engineer",
"company" : "ACI Worldwide",
"city" : "Norcross",
"state" : "GA",
"country" : "US",
"formattedLocation" : "Norcross, GA",
"source" : "ACI Worldwide",
"date" : "Thu, 19 Dec 2013 11:51:00 GMT",
"snippet" : "\u2022 Experienced <b>Java<\/b> engineer for developing commercial... development experience \u2022 2 years of professional <b>Java<\/b> development with 2+ years of J2EE. \u2022 2 years of... ",
"url" : "http:\/\/www.indeed.com\/viewjob?jk=7ac5988d9e5f0990&qd=TOIxqcl1xBNMbg2vKTNLcp5QUXHMUbDABF-wK7BxUqwiE8mPbZ2XU9t5kjdQrB6FlsFPgK13DhJYpBc84nTJQYrzCHZtERhjBNeGyZxL6jI&indpubnum=4675158811138546&atk=18cme6tj519rh3c6",
"onmousedown" : "indeed_clk(this, '1050');",
"latitude" : 33.93956,
"longitude" : -84.20879,
"jobkey" : "7ac5988d9e5f0990",
"sponsored" : false,
"expired" : false,
"formattedLocationFull" : "Norcross, GA",
"formattedRelativeTime" : "6 days ago"
}
]
};
$("#myGrid").jqGrid({
//url: "testData.xml",
dataType:"json",
data : myStr,
jsonReader: {
repeatitems: false,
root: "results"
},
colNames: ["Trending Jobs"],
colModel: [
{ name: "url" }
],
rowNum: 5,
rowList: [5, 10, 20, 100, 10000],
pager: "#pager",
gridview: true,
rownumbers: true,
viewrecords: true,
height: "auto",
loadonce: true
});
I tried to read the data using jsonreader, set the data type as "json" and root as "results".
There are no data populated in jqgrid, Could anybody educate me, what I am missing here ?
The error in your code there are because of small misunderstanding about the meaning of the options jqGrid. If you define a variable like myStr in your code
var myStr = {
"version" : 2,
...
"results" : [
{
...
}
]
};
you don't use JSON. It's just usage of object literals to create new object. Such syntax is the most simple and effective way to create and initialize an object in JavaScript. Only if properties have special characters it's required to enclose property names in " or '. So the same code can be rewritten as
var myStr = {
version : 2,
...
results : [
{
...
}
]
};
So I wanted to stress that the above don't use JSON at all. The correct value of datatype parameter (not dataType) should be "local" instead of "json". The options jsonReader or loadonce will be ignored in the case. The input data should be array of items specified by data option of jqGrid.
So the fixed code should be like the following
$("#myGrid").jqGrid({
datatype: "local",
data: myStr.results,
colNames: ["Trending Jobs"],
colModel: [
{ name: "url" }
],
rowNum: 5,
rowList: [5, 10, 20, 100, 10000],
pager: "#pager",
gridview: true,
rownumbers: true,
viewrecords: true,
height: "auto"
});
(see the demo).
If your real code do load the data from the server it should use url parameter. In the case the options jsonReader or loadonce can be used and the code will be like below
$("#myGrid").jqGrid({
url: "Sri2.json",
datatype: "json",
jsonReader: {
repeatitems: false,
root: "results"
},
loadonce: true,
colNames: ["Trending Jobs"],
colModel: [
{ name: "url" }
],
rowNum: 5,
rowList: [5, 10, 20, 100, 10000],
pager: "#pager",
gridview: true,
rownumbers: true,
viewrecords: true,
height: "auto"
});
(see another demo).
You code have strange properties like onmousedown. If you need to set onmousedown property on some cell you can use cellattr property in colModel. It allows you to set any additional property to <td> element which represent the cell of the grid. For example one more demo uses the following code
function indeed_clk (obj, id) {
alert("onmousedown with id=" + id);
}
$(function () {
var myStr = {
...
"results" : [
{
...
"onmousedown" : "indeed_clk(this, '1050');",
...
}
]
};
$("#myGrid").jqGrid({
datatype: "local",
data: myStr.results,
colNames: ["Trending Jobs"],
colModel: [
{
name: "url",
title: false,
cellattr: function (rowId, cellValue, rawObject) {
if (rawObject.onmousedown) {
return 'onmousedown="' + rawObject.onmousedown + '"';
}
}
}
],
rowNum: 5,
rowList: [5, 10, 20, 100, 10000],
pager: "#pager",
gridview: true,
rownumbers: true,
viewrecords: true,
height: "auto"
});
});
It set onmousedown attribute which calls global function indeed_clk. onmousedown will be set on the cells in the column url using cellattr property.
I have an external jsp page(a menu) and a DOJO table in my div. When I tried to applyoverflow:auto; on the div, I am seeing 2 scroll bars. One for the table and the other for the menu. How do I make the menu and the table scroll for a single scroll bar?
<div id="table">
<jsp:include page="searchgroup.jsp"></jsp:include>
<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">
</div>
</div>
This is my CSS
#grid1{
height: 85%;
width: 104%;
overflow-x:auto;
}
#table{
height:90%;
width:104%;
overflow-x:auto;
}
<script>
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"); // scan page for widgets and instantiate them
var gridLayout = [
{
name : "S. No.",
classes : "title",
width : "70%",
get : siFormatter,
filterable : false
}, {
name : "Site Id",
classes : "title",
field : "siteId",
width : "70%"
}, {
name : "IP/Phone No.",
classes : "title",
field : "devType",
width : "120%"
}, {
name : 'Site Name',
classes : "title",
field : "name",
fields : [ 'company', 'name' ],
formatter : formatLink,
width : "110%"
}
</script>
because you applied overflow: auto on both of them
you are supposed to use that on one of them not both of them
I have kendo grid in my application.And in my grid filterable is true.In grid one row has numeric text-box in filter,when we click on spinners it is showing infinity values.So I want to give some limit for numeric text-boxes in filter.How to give some limit for numeric text boxes in grid filter.?
My grid code is
var grid = $("#grid").kendoGrid({
dataSource: {
type : "odata",
transport : {
read: "http://demos.kendoui.com/service/Northwind.svc/Orders"
},
schema : {
model: {
fields: {
OrderID : { type: "number" },
Freight : { type: "number" },
ShipName : { type: "string" },
OrderDate: { type: "date" },
ShipCity : { type: "string" }
}
}
},
pageSize : 10
},
filterable: true,
sortable : true,
pageable : true,
columns : [
{
field : "OrderID",
filterable: false
},
"Freight",
{
field : "OrderDate",
title : "Order Date",
width : 100,
format: "{0:MM/dd/yyyy}"
},
{
field: "ShipName",
title: "Ship Name",
width: 200
},
{
field: "ShipCity",
title: "Ship City"
}
]
}).data("kendoGrid");
Once try this
filterMenuInit: function(e) {
var numeric = e.container.find("[data-role=numerictextbox]").data("kendoNumericTextBox");
if (numeric) {
numeric.min(0);
}
}