I am traversing through jqGrid. When I press row action button it should get current pressed row data, to do this I need to get row id of that row when clicked.
<tr role="row" id="1" tabindex="-1" class="jqgrow ui-row-ltr ui-widget-content">
This is closest tr and I can reach till this tr easily using below code.
$("#rangemaster").children("tr.jqgrow")
But when I try to get id its showing undefined.
$("#rangemaster").children("tr.jqgrow").attr("id")
I want to pic id value of that tr.jqgrow.
You can find tr with class name and catch your attribute id using jQuery object $(this).
$("#grid").find("tr.jqgrow").each(function(index) {
console.log(index + ": " + $(this).attr("id"));
});
Example:
var mydata = [{
id: "1",
label: "No 1",
number: "123",
status: "OPEN",
},
{
id: "6",
label: "No 2a",
number: "222",
status: "Close"
}
];
var grid = $("#grid");
grid.jqGrid({
datatype: "local",
colNames: ['Col-Id', 'Col-Label', 'Col-Number', 'Col-Status'],
colModel: [{
name: 'id',
index: 'id',
width: 60,
sorttype: "int"
},
{
name: 'label',
index: 'label',
width: 180,
sorttype: "string"
},
{
name: 'number',
index: 'number',
width: 120,
sorttype: "float"
},
{
name: 'status',
index: 'status',
width: 120,
sorttype: "string"
}
],
gridview: true,
sortname: 'id',
treeGrid: true,
treedatatype: 'local',
height: 'auto',
pager: "#gridPager"
});
grid[0].addJSONData({
total: 1,
page: 1,
records: mydata.length,
rows: mydata
});
$("#grid").find("tr.jqgrow").each(function(index) {
console.log(index + ": " + $(this).attr("id"));
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/jqgrid/5.8.0/css/ui.jqgrid.min.css">
<script type="text/javascript" charset="utf8" src="https://cdnjs.cloudflare.com/ajax/libs/jqgrid/5.8.0/js/jquery.jqGrid.min.js"></script>
<table id="grid"></table>
<div id="gridPager"></div>
Related
Is there is any way to create widgets in kendo grid cell template? here is the sample code.
columns: [{
field: "Name",
title: "Contact Name",
width: 100
},
{
field: "Cost",
title: "Cost",
template: "<input value='#: Cost #'> </input>",// input must be an numerical up down.
}]
I want to create a numerical up down for cost column.
here is the demo
Use the "editor" property in your field definition. You have to specify a function that will append the widget to the row/bound cell.
Here's an example where I put a drop downlist in each of the rows of a grid:
$('#grdUsers').kendoGrid({
scrollable: true,
sortable: true,
filterable: true,
pageable: {
refresh: true,
pageSizes: true
},
columns: [
{ field: "Id", title: "Id", hidden: true },
{ field: "Username", title: "UserName" },
{ field: "FirstName", title: "First Name" },
{ field: "LastName", title: "Last Name" },
{ field: "Email", title: "Email" },
{ field: "Team", title: "Team", editor: teamEdit, template: "#=Team ? Team.Name : 'Select Team'#" },
{ command: { text: "Save", click: saveEmployee }, width: '85px' },
{ command: { text: "Delete", click: deleteEmployee }, width: '85px' }
],
editable: true,
toolbar: [{ name: "create-user", text: "New Employee" }]
});
function teamEdit(container, options) {
$('<input required data-text-field="Name" data-value-field="Id" data-bind="value:' + options.field + '"/>')
.appendTo(container)
.kendoDropDownList({
autoBind: false,
optionLabel: {
Name: "Select Team",
Id: ""
},
dataTextField: "Name",
dataValueField: "Id",
dataSource: model.getAllTeams()
});
}
You can define kendo numeric textbox binding in template. Also define databound function where explictly call kendo.bind method.
I have updated your fiddle as below:
template: "<input value='#=Cost#' data-bind='value:Cost' type='number' data-role='numerictextbox' />"
Updated fiddle
<kendo-grid-column title="Billed" field="billed" class="text-center" id="">
<ng-template kendoGridCellTemplate let-dataItem="dataItem">
<input type="text" width="10px" value="45">
<a class="anchor_pointer">{{dataItem.billed }}</a>
</ng-template>
</kendo-grid-column>
I'm trying to update a highcharts highstock chart with live data from a json file on my server.
now I have a chart that gets its data from a json file (that I create with php that requests the data from my MySQL database) like so:
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>OKcoin Price LTCCNY</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
$.getJSON('json/lastTradesOkcoinLTCCNY.json', function(data) {
Highcharts.setOptions({
global: {
useUTC: false
}
});
// create the chart
$('#container').highcharts('StockChart', {
rangeSelector : {
selected : 1
},
title : {
text : 'OkCoin Price LTCCNY'
},
rangeSelector: {
buttons: [{
type: 'hour',
count: 1,
text: '1h'
}, {
type: 'hour',
count: 6,
text: '6h'
}, {
type: 'hour',
count: 12,
text: '12h'
}, {
type: 'hour',
count: 24,
text: '24h'
}, {
type: 'day',
count: 3,
text: '3d'
}, {
type: 'day',
count: 7,
text: '7d'
}, {
type: 'all',
text: 'All'
}],
selected: 2
},
xAxis: {
gridLineWidth: 1,
title: {
enabled: true,
text: 'Time',
style: {
fontWeight: 'normal'
}
}
},
yAxis: [{
title: {
text: 'Price LTCCNY'
},
gridLineWidth: 1,
minorTickInterval: 'auto',
minorTickColor: '#FEFEFE',
labels: {
align: 'right'
}
}],
plotOptions: {
series: {
lineWidth: 1
}
},
tooltip: {
valueDecimals: 5,
valuePrefix: '$ '
},
series : [{
name : 'LTCCNY Price',
data : data,
dataGrouping : {
units : [
['minute',
[1, 5, 10, 15, 30]
], ['hour', // unit name
[1]
]
]
}
}]
});
});
});
</script>
</head>
<body>
<script src="../Highstock/js/highstock.js"></script>
<script src="../Highstock/js/modules/exporting.js"></script>
<div id="container" style="height: 500px; min-width: 500px"></div>
</body>
</html>
So far no problems, I get a chart from the json file. But of course it doesn't update if new data becomes available (only if I reload the page) .
What I want to do is after loading this chart, add live data to it as it becomes available.
something like this example, but instead of random data the chart will be updated with data from a (second) live updating json file on my webserver. The json file will be created by php (this part is working just fine) But I can't figure out how to add the data from the json file to the my existing highstock chart.
I also found
this this example on highcharts.com and that more or less does what I try to do, but I can't integrate the 'requestData' function into my existing chart.
So what I want to do is use the 'requestData' function from the second example with the high stock chart I already have. My second json file (with the live data) looks the same as in the second example (timestamp, price):
[1389022968000,173.3]
Can anyone help me a bit?
nevermind, I figured it out myself...
here's my solution:
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>OKCoin LTCCNY Price</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript">
var chart; // global
function requestData() {
$.ajax({
url: 'tickOkCoinLTCCNY.json',
success: function(point) {
var series = chart.series[0],
shift = series.data.length > 2; // shift if the series is longer than 20
// add the point
chart.series[0].addPoint(eval(point), true, shift);
// call it again after one second
setTimeout(requestData, 10000);
},
cache: false
});
}
$(function() {
$.getJSON('../okcoin/json/lastTradesOkcoinLTCCNY.json', function(data) {
// set the allowed units for data grouping
var groupingUnits = [[
'minute', // unit name
[1,5,15,30] // allowed multiples
], [
'hour',
[1, 2, 3, 4, 6]
]];
// create the chart
chart = new Highcharts.StockChart({
chart: {
renderTo: 'container',
events: {
load: requestData
}
},
rangeSelector: {
buttons: [{
type: 'hour',
count: 1,
text: '1h'
}, {
type: 'hour',
count: 6,
text: '6h'
}, {
type: 'hour',
count: 12,
text: '12h'
}, {
type: 'hour',
count: 24,
text: '24h'
}, {
type: 'day',
count: 3,
text: '3d'
}, {
type: 'day',
count: 7,
text: '7d'
}, {
type: 'all',
text: 'All'
}],
selected: 2
},
title: {
text: 'OKCoin LTCCNY Price'
},
xAxis: {
type: 'datetime',
gridLineWidth: 1,
title: {
enabled: true,
text: 'Time',
style: {
fontWeight: 'normal'
}
}
},
yAxis: [{
title: {
text: 'LTCCNY'
},
lineWidth: 2
}],
series: [{
name: 'LTCCNY',
data: data,
dataGrouping: {
units: groupingUnits
}
}]
});
});
});
</script>
</head>
<body>
<script src="../Highstock/js/highstock.js"></script>
<script src="../Highstock/js/modules/exporting.js"></script>
<div id="container" style="height: 500px; min-width: 500px"></div>
</body>
</html>
I am getting a JSON.parse: unexpected character exception while I am trying to read a local JSON in my JQGrid.
<script type="text/javascript">
var jsondata = {
"totalpages": "1",
"currpage": "1",
"totalrecords": "2",
"invdata" : [
{"name":"New York City", "country":"USA", "continent":"NorthAmerica"},
{"name":"Paris", "country":"France", "continent":"Europe"}
]
};
$(document).ready(function() {
$("#grid").jqGrid({ data: jsondata,
datatype: "json",
colNames: ["Name", "Country", "Continent"],
colModel: [{
name: 'name',
index: 'name',
editable: true,
}, {
name: 'country',
index: 'country',
editable: true,
}, {
name: 'continent',
index: 'continent',
editable: true,
}],
pager: '#pager',
jsonReader : {
root:"invdata",
page: "currpage",
total: "totalpages",
records: "totalrecords",
repeatitems: false,
id: "0"
},
caption:"Dynamic hide/show column groups"
}).navGrid("#pager",{edit:false,add:false,del:false});
jQuery("#hc").click( function() { jQuery("#grid").jqGrid('hideCol',["continent"]); });
jQuery("#sc").click( function() { jQuery("#grid").jqGrid('showCol',["continent"]); });
});
</script>
I have tried to lookup in the jqgrid Wiki but still unable to figure out what's wrong. Is there a problem with the jsonReader? I have checked related questions but it didn't help much.
Instead of giving "jsondata" as a parameter to "data" for the jqgrid, give data : jsondata.invdata
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
In the following example, I would like to replace the hard-coded items array with a call to a jsonstore with with same items read dynamically. I have tried referencing the store through xtype but get an error that Object has no method 'getItemId' - please let me know what I am doing wrong and many thanks for your help
Ext.define("MyApp.view.Main", {
extend: 'Ext.ux.slidenavigation.View',
requires: [
'Ext.Container',
'Ext.MessageBox',
'Ext.Panel',
'Ext.Toolbar',
'Ext.event.publisher.Dom'
],
config: {
fullscreen: true,
slideSelector: 'x-toolbar',
selectSlideDuration: 200,
list: {
maxDrag: 400,
width: 200,
items: [{
xtype: 'toolbar',
docked: 'top',
ui: 'light',
title: {
title: 'Navigation',
centered: false,
width: 200,
left: 0
}
}]
},
/***************************************************************/
/* Want to replace this items array with dynamic call to store */
/***************************************************************/
items: [{
title: 'Item 1',
slideButton: {
selector: 'toolbar'
},
items: [{
xtype: 'toolbar',
title: 'Item 1',
docked: 'top'
},{
xtype: 'panel',
html: '<img src="resources/images/guide.jpg" width="100%" />'
}]
},{
title: 'Item 2',
slideButton: {
selector: 'toolbar'
},
items: [{
xtype: 'toolbar',
title: 'Item 2',
docked: 'top'
},{
xtype: 'panel',
html: '<img src="resources/images/guide.jpg" width="100%" />'
}]
}]
}
Store sample
Ext.define('MyApp.store.Navigation', {
extend: 'Ext.data.Store',
alias: 'widget.navstore',
requires: [
'MyApp.model.Navigation'
],
config: {
model: 'InspectionApp.model.Navigation',
storeId: 'navStore',
proxy: {
type: 'ajax',
url: '/path/to/navigation.json',
reader: {
type: 'json',
rootProperty: 'items'
}
},
grouper: {
property: 'group',
sortProperty: 'groupOrder'
}
}
});
json sample
[
{
"title": "Item 1",
"slideButton": "{selector: 'toolbar'}",
"items": "[{xtype: 'toolbar',title: 'Item 1',docked: 'top'},{xtype: 'panel',html: '<img src='resources/images/guide.jpg' width='100%' />'}]",
"handler": ""
},
{
"title": "Item 2",
"slideButton": "{selector: 'toolbar'}",
"items": "[{xtype: 'toolbar',title: 'Item 2',docked: 'top'},{xtype: 'panel',html: '<img src='resources/images/guide.jpg' width='100%' />'}]",
"handler": ""
}
]
Assuming your store is loading correctly, you can get a reference to it by calling
Ext.getStore('navStore')
or by assigning your store to a variable:
var yourStore = Ext.define('MyApp.store.Navigation', {
extend: 'Ext.data.Store',
alias: 'widget.navstore',
requires: [
'MyApp.model.Navigation'
],
config: {
model: 'InspectionApp.model.Navigation',
storeId: 'navStore',
proxy: {
type: 'ajax',
url: '/path/to/navigation.json',
reader: {
type: 'json',
rootProperty: 'items'
}
},
grouper: {
property: 'group',
sortProperty: 'groupOrder'
}
}
});
To populate the items object I would put it in a container:
{
xtype: 'container',
id: 'container_id',
}
then
for (var i = 0; Ext.getStore('navStore').getCount(); ++i){
var record = Ext.getStore('navStore').getAt(i);
var myComponent = Ext.create(...
//make the component you want to add with the data from the record
);
Ext.ComponentQuery.query('#container_id')[0].add(myComponent);
}