I have a json string which i am using to populate the jqgrid. in the string i have one element which is a hyperlink. the problem is that if i use this string then the grid does not load at all ! here is my code
var json = '{"total": "","page": "1","records": "","rows" : [{"id" :"1", "cell" :["Quantum of Solace","142456", "1234.89", "1234"]},{"id" :"2", "cell":["01/04/2013", "7741", "007997.66", "234"]},{"id" :"3", "cell":["06/08/2013", "78976", "2329.336", "234"]},{"id" :"4", "cell":["01/01/2012", "6678", "2154.22", "1234"]},]}';
jQuery(document).ready(function () {
jQuery("#list").jqGrid({
datatype: 'jsonstring',
datastr:json,
colNames: ['Date', 'Account ', 'Amount', 'Code'],
colModel: [
{ name: 'adate', index: 'adate', width: 90, sorttype: 'date', datefmt: 'Y-m-d' },
{ name: 'account', index: 'account', width: 80, align: 'right', sorttype: 'int' },
{ name: 'amount', index: 'amount', width: 80, align: 'right', sorttype: 'float' },
{ name: 'code', index: 'code', width: 80, align: 'right', sorttype: 'int' }
],
pager: "#pager",
toppager: true,
rowNum: 10,
rowList: [10, 20, 30],
toolbar: [true, "top"],
sortorder: "desc",
viewrecords: true,
gridview: true,
imgpath: 'F:/profile/ProgramFiles/JQGrid/jquery-ui-1.10.3.custom/development-bundle/themes/redmond/images',
autoencode: true,
height: '100%',
caption: "My first grid"
}).navGrid('#pager', { edit: true, add: true, del: true, search: true, refresh: true, cloneToTop: true });
});
do i need to make a change in the colModel ? is that the reason why the grid does not load ? if i replace the link with random text, the grid works just fine.
please help, i really need to implement hyperlinks in the grid and i have to do it on the backend
First of all the usage of imgpath: 'F:/profile/...' options have the same effect like the usage of for example myName: 'user2334092'. Both options will be just ignored by jqGrid as unknown. I wrote you about it in my previous answer.
If you need to have a column of grid with hyperlink which data come from the server you can do the following. You need place all information which you need in the hyperlink as data. For example
[
{
"id": 10,
"href": "http://www.google.com",
"linktext": "Quantum of Solace",
"adate": "2012-12-15",
"account": 142456,
"amount": 1234.89,
"code": 1234
},
{
"id": 20,
"href": "https://stackoverflow.com/questions/17351495/",
"linktext": "Your question",
"adate": "2013-06-28",
"account": 7741,
"amount": 7997.66,
"code": 234
}
]
Then you can use for example
colNames: ["", "Date", "Account", "Amount", "Code"],
colModel: [
{ name: "linktext", width: 200, sortable: false, search: false,
formatter: function (cellValue, options, rowObject) {
return "<a href='" + rowObject.href + "'>" +
$.jgrid.htmlEncode(cellValue) + "</a>";
}},
{ name: "adate", width: 90, formatter: "date", sorttype: "date" },
{ name: "account", width: 80, formatter: "integer", sorttype: "int",
align: "right" },
{ name: "amount", width: 80, formatter: "number", sorttype: "float",
align: "right" },
{ name: "code", width: 80, formatter: "integer", sorttype: "int",
align: "right" }
]
to read and display the data. Usage the function $.jgrid.htmlEncode make you sure that you can currectly display any text in the link event textes like </td>foo "bar's which contains symbols having special meaning in HTML. You can remove formatter: "integer" and formatter: "integer" if you don't want to display numbers with thouthand separator and with decimal separator specified in jqGrid locale file (like from grid.locale-en.js). You can use formatoptions to specify the options of the formatters (see the documentation). The demo uses the code and it display the following results
Related
I'm trying to add subgrids to an existing jqGrid.
When I expand a parent row, the URL is called and the JSON response looks good (to my eyes) but it is not being bound to the sub grid rows.
If I call the web service directly by pasting the URL in a browser, the response looks good.
This is the full jqGrid definition:
/* +++ Group Grid Definition +++ */
$("#<%= id %>_groupTable").jqGrid({
loadonce: true,
datatype: 'local',
//sortable: true,
gridview: true,
editurl: "clientArray",
autowidth: true,
rowNum: 12000,
height: 150,
multiselect: false,
hidegrid: false,
pgbuttons: false,
pginput: false,
sortname: "Date",
sortorder: "desc",
jsonReader: {
root: "inbox",
page: "page",
total: "total",
records: "records",
id: "id",
repeatitems: false,
subgrid: { repeatitems: true }
},
toolbar: [true, "bottom"],
colModel: [
{
name: 'userGroupId',
label: '{{VIEW_LABEL}}',
index: 'userGroupId',
width: 50,
fixed: true,
hidden: true,
//sortable: false,
align: 'center'
}, {
name: 'desc',
label: '{{NAME_LABEL}}',
index: 'desc',
width: 130,
align: 'center',
sorttype: 'text'
}],
hidegrid: false,
gridComplete: function () {
$('#<%= id %> .loading').remove();
$('#<%= id %>_groupTable').jqGrid('setSelection', 1);
},
loadComplete: styleGroupRows,
afterInsertRow: styleGroupRows,
subGrid: true,
subgridtype: 'json',
subGridUrl: '/ws/users/groupusers',
subGridModel: [
{
name: ['Name'],
width: [200],
params: ['userGroupId']
}]
}).jqGrid('bindKeys', {
'scrollingRows': true
});
This is the JSON response from the web service:
{'rows':['User 1312','User 1316','User 1286','User 1149']}
I'm expecting a single column of user names in the sub grids but only the column headers appear.
Your subGrid response does not match the rules.
Try with the following response:
{"rows":[{"id":"1","cell":["User 1312"]},{"id":"2","cell":["User 1316"]}]}
// I am using a JQXGrid, and while populating the grid with valid JSON string (I checked) it forms the columns perfectly (headers, footers, pageing, etc) but all the data is listed under the first column. I have been trying different settings for the last while and possibly a second set of eyes can see the error.
// Configure data source for data grid,...
var LocationDataSource =
{
datatype: "json",
datafields: [
{ name: 'Date' },
{ name: 'ProductCode' },
{ name: 'StoreNum' },
{ name: 'ProductQty', type: 'int' }
],
localdata: LocationData
};
// Configure Data Adapter and apply JSON data to it,...
var LocationDataAdapter = new $.jqx.dataAdapter(LocationDataSource);
// Apply data source to grid,...
$("#jqxLocationGrid").jqxGrid(
{
width: 900,
source: LocationDataAdapter,
pageable: true,
rowsheight: 50,
autoheight: true,
sortable: true,
altrows: true,
enabletooltips: true,
selectionmode: 'multiplecellsadvanced',
columns: [
{ text: 'Date', datafield: 'Date', width: 250 },
{ text: 'Product Code', datafield: 'ProductCode', width: 250 },
{ text: 'Store Number', datafield: 'StoreNum', width: 250 },
{ text: 'Product Qty', datafield: 'ProductQty', width: 250 }
]
});
I had the same issue and i fixed it, I forgot to add jqx.base.css to the default.aspx.
Trying to set a default sort column on my kendo UI grid from a local datasource. I've read all over that I should be putting:
sort: { field: "price", dir: "desc" }
onto the data source. I've tried this and it still isn't working (see bottom of following example).
Here's my code in full, where am I going wrong?
$('#grid').kendoGrid({
dataSource: [
{
date: "Feb 13 2014",
price: 5,
},
{
date: "Feb 15 2014",
price: 7,
},
{
date: "Feb 12 2014",
price: 6,
}
],
height:500,
sortable: true,
pageable: false,
columns: [
{
field: "date",
title: "Date"
},
{
field: "price",
title: "Price",
}
],
sort: {field: "price", dir: "desc"}
});
You are defining the sort line in the wrong place. You're putting it as one of the grid's properties, but it is (as you said) one of the datasource's property.
Put it as a child of the datasource property:
$('#grid').kendoGrid({
dataSource: {
data: [{
date: "Feb 13 2014",
price: 5,
}, {
date: "Feb 15 2014",
price: 7,
}, {
date: "Feb 12 2014",
price: 6,
}],
sort: {
field: "price",
dir: "desc"
}
},
height: 500,
sortable: true,
pageable: false,
columns: [{
field: "date",
title: "Date"
}, {
field: "price",
title: "Price",
}],
});
If it still doesn't work, I can provide a jsFiddle for you to work around with.
if you are using Telerik MVC Control which is finally rendered to Kendo UI
.DataSource(dataSource => dataSource
.Ajax()
.Sort(sort => sort.Add("City").Ascending()) // <-- initial sort expression
.Read(read => read.Action("Index", "Home"))
)
I am using Kendo UI Line chart from Web Dataviz package for generate a Graph with 500+. but the load of the graph is too lazy. It takes like 25 seconds for the graph to be generated.
I am using a date for Category Axis and a Decimal Value for the serie with a odata datasource.
Can I optimize the load time of the graph?
$("#chart").kendoChart({
theme: $(document).data("kendoSkin") || "default",
dataSource: {
type: "odata",
transport: {
read: crudServiceBaseUrl + "/Odata/TestODataService.svc/EGauges"
},
serverFiltering: true,
serverSorting: true,
sort: { field: "DateData", dir: "asc"},
filter: [
{field: "From", operator: "eq", value: 422 },//400+
{ field: "Id", operator: "eq", value: parseInt(id) },
{ field: "Intervalo", operator: "eq", value: 23 },
{ field: "Tipo", operator: "eq", value: 'm' }
],
title: {
text: ""
},
legend: {
position: "bottom"
},
seriesDefaults: {
type: "area"
},
series: [{
field: "Value",
name: "Value"
}],
categoryAxis: {
field: "DateData",
labels: {
visible: false,
rotation: -90
}
},
axisDefaults: {
visible: true,
majorGridLines: { visible: false }
},
tooltip: {
visible: true
}
});
Here is how the odata service is returning data:
jQuery1704278529312834345_1357310335401({"d" : {
"results": [
{
"__metadata": {
"uri": "http://localhost/Prosol.Web/Odata/TestODataService.svc/EGauges(18)",
"type": "TestOpenErpInterfaz.Web.TestEntityDataSource_EGauge"
},
"EGaugeID": 18,
"From": 422,
"Id": 18,
"Tipo": "m",
"Intervalo": 23,
"DateData": "\/Date(1357310820000)\/",
"Value": "3.72",
"TotalKw": "0",
"TotalCosto": "0.00",
"TotalKwGen": "203.23999999999999999999999999",
"TotalCostoGen": "16.259199999999999999999999999",
"FechaDisplay": "Ene 4, 2013 14:47"
},........
], "__count": "421"
}
})
Finally I Use FlotCharts, For some reason the KendoUI Chart laoad data very lazy... I use Kendo Ui Datasource for read data from Web Service and load on FloatChart...
http://www.flotcharts.org/
This is simple, fast, and freeware
I need some idea, about how to implement a subgrid in the following sceaniro.
The following is the json data that I want to display in the JQuery Grid and Subgrid.
Basically I am getting an object called "Contact" that has a collection called "actionSet".
{
"total" : "10",
"page" : "1",
"records" : "78",
"rows" : [ {
"comment" : null,
"givenName" : "Contact A",
"familyName" : "A",
"actionSet" : [ {
"actionID" : 1,
"actionDueDate" : "2012-12-08",
"actionNote" : "Action 1"
}, {
"actionID" : 2,
"actionDueDate" : "2012-12-08",
"actionNote" : "Action 2"
} ]
} ...]
}
I want eache Grid row to display the "Contact" and the subgris associated with the grid should display "actionSet" collection.
When a particular row in the Grid is selected, I do not want to make a server call to get the associated actions, as they are allready present in the "actionSet".
I have got the Grid working, displaying the "Contacts" nicely, but I get confused while implement the subgrid, as how to get the data for it, as its allready available in json.
jq(function() {
jq("#grid").jqGrid({
url:'/smallworks/project/getall.do',
datatype: 'json',
mtype: 'GET',
colNames:['Id', 'First Name', 'Last Name'],
colModel:[
{name:'id',index:'id', width:55,editable:false,editoptions: {readonly:true,size:10},hidden:true},
{name:'givenName',index:'givenName', width:100,editable:true, editrules:{required:true}, editoptions:{size:10}},
{name:'familyName',index:'familyName', width:100,editable:true, editrules:{required:true}, editoptions:{size:10}}
],
postData: {
},
rowNum:20,
rowList:[20,40,60],
height: 200,
autowidth: true,
rownumbers: true,
pager: '#pager',
sortname: 'id',
viewrecords: true,
sortorder: "asc",
caption:"Contacts",
emptyrecords: "Empty records",
loadonce: false,
loadComplete: function() {
},
Is this achievable?
Do I need to parse JSON data specially for the subgrid?
How can this be achieved?
I suggest that you save information from actionSet in an object which you can easy access later. For example you can use userData parameter and fill the userdata part of JSON data inside of beforeProcessing. The create subgrid you can follow the answer or another one.
The demo demonstrate the implementation approach:
It uses the following code
var mainGridPrefix = "s_";
$("#grid").jqGrid({
url: "Adofo.json",
datatype: "json",
colNames: ["First Name", "Last Name"],
colModel: [
{ name: "givenName" },
{ name: "familyName" }
],
cmTemplate: {width: 100, editable: true, editrules: {required: true},
editoptions: {size: 10}},
rowNum: 20,
rowList: [20, 40, 60],
pager: "#pager",
gridview: true,
caption: "Contacts",
rownumbers: true,
autoencode: true,
height: "100%",
idPrefix: mainGridPrefix,
subGrid: true,
jsonReader: { repeatitems: false },
beforeProcessing: function (data) {
var rows = data.rows, l = rows.length, i, item, subgrids = {};
for (i = 0; i < l; i++) {
item = rows[i];
if (item.actionSet) {
subgrids[item.id] = item.actionSet;
}
}
data.userdata = subgrids;
},
subGridRowExpanded: function (subgridDivId, rowId) {
var $subgrid = $("<table id='" + subgridDivId + "_t'></table>"),
pureRowId = $.jgrid.stripPref(mainGridPrefix, rowId),
subgrids = $(this).jqGrid("getGridParam", "userData");
$subgrid.appendTo("#" + $.jgrid.jqID(subgridDivId));
$subgrid.jqGrid({
datatype: "local",
data: subgrids[pureRowId],
colNames: ["Due Date", "Note"],
colModel: [
{ name: "actionDueDate", formatter: "date", sorttype: "date" },
{ name: "actionNote" }
],
sortname: "actionDueDate",
height: "100%",
rowNum: 10000,
autoencode: true,
autowidth: true,
jsonReader: { repeatitems: false, id: "actionID" },
gridview: true,
idPrefix: rowId + "_"
});
}
});
UPDATED: The JSON data used in the demo one can see below. I added id property which is required for jqGrid. I used actionID as the id of the subgrids:
{
"total": "10",
"page": "1",
"records": "78",
"rows": [
{
"id": 10,
"comment": null,
"givenName": "Contact A",
"familyName": "A",
"actionSet": [
{
"actionID": 1,
"actionDueDate": "2012-12-08",
"actionNote": "Action 1"
},
{
"actionID": 2,
"actionDueDate": "2012-12-09",
"actionNote": "Action 2"
}
]
},
{
"id": 20,
"comment": null,
"givenName": "Contact B",
"familyName": "B",
"actionSet": [
{
"actionID": 3,
"actionDueDate": "2012-12-11",
"actionNote": "Action 3"
},
{
"actionID": 4,
"actionDueDate": "2012-12-10",
"actionNote": "Action 4"
}
]
}
]
}