I created a table
<!--Begin::Datatable-->
<table class="datatable-table" id="kt_datatable">
<thead class="datatable-head">
<tr>
<th>ID</th>
<th>Nom</th>
<th>Univers</th>
<th>Groupe</th>
<th>Propriété</th>
<th>Action</th>
</tr>
</thead>
</table>
<!--End::Datatable-->
Added a js script to gain some Datatable magics
"use strict";
var dataSet = [{
"groupName": "test",
"univers": "JARDINAGE",
"name": "#A DEFINIR",
"keywords": "test",
"id": 1,
"hasBattery": 1,
"hasBulb": 1,
"hasMemory": 1,
"isFurniture": 1,
"isToxic": 1,
"isElectronic": 1,
"obsolete": 0
},
{
"groupName": "#A DEFINIR",
"univers": "#A DEFINIR",
"name": "PERCEUSE VISSEUSE",
"keywords": null,
"id": 2,
"hasBattery": 0,
"hasBulb": 0,
"hasMemory": 0,
"isFurniture": 0,
"isToxic": 0,
"isElectronic": 0,
"obsolete": 0
}
];
var DatatablesBasic = function () {
var initTableCat = function () {
var table = $('#kt_datatable');
table.DataTable({
responsible: true,
data: dataSet,
"columnDefs":
[{
"targets": [0],
"visible": false,
"searchable": false
},
{
"targets": [1],
"searchable": true,
},
{
"targets": [2],
"searchable": true,
},
{
"targets": [3],
"false": true,
},
{
"targets": [4],
"searchable": false,
"visible": true,
}],
"columns": [{
"data": "id",
"name": "id",
"autoWidth": true
},
{
"data": "univers",
"name": "univers",
"autoWidth": true
},
{
"data": "groupName",
"name": "groupName",
"autoWidth": true
},
{
"data": "name",
"name": "name"
},
{
"data": function (data) {
var has_battery = data.hasBattery;
var is_electronic = data.isElectronic;
var is_toxic = data.isToxic;
var has_memory = data.hasMemory;
var is_furniture = data.isFurniture;
var has_bulb = data.hasBulb;
var finalProprety = 0;
if (is_electronic) {
finalProprety += 1;
}
if (has_battery) {
finalProprety += 1;
}
if (is_toxic) {
finalProprety += finalProprety += 1;
}
if (has_memory) {
finalProprety +=finalProprety += 1;
}
if (is_furniture) {
finalProprety +=finalProprety += 1;
}
if (has_bulb) {
finalProprety +=finalProprety += 1;
}
return finalProprety;
}
},
{
"name": "action",
"searchable": false,
"autoWidth": true,
"orderable": false,
"defaultContent": '\
<a href="javascript:;" class="btn btn-sm btn-clean btn-icon mr-2" title="Edit details">\
<span class="svg-icon svg-icon-md">\
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="24px" height="24px" viewBox="0 0 24 24" version="1.1">\
<g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">\
<rect x="0" y="0" width="24" height="24"/>\
<path d="M8,17.9148182 L8,5.96685884 C8,5.56391781 8.16211443,5.17792052 8.44982609,4.89581508 L10.965708,2.42895648 C11.5426798,1.86322723 12.4640974,1.85620921 13.0496196,2.41308426 L15.5337377,4.77566479 C15.8314604,5.0588212 16,5.45170806 16,5.86258077 L16,17.9148182 C16,18.7432453 15.3284271,19.4148182 14.5,19.4148182 L9.5,19.4148182 C8.67157288,19.4148182 8,18.7432453 8,17.9148182 Z" fill="#000000" fill-rule="nonzero"\ transform="translate(12.000000, 10.707409) rotate(-135.000000) translate(-12.000000, -10.707409) "/>\
<rect fill="#000000" opacity="0.3" x="5" y="20" width="15" height="2" rx="1"/>\
</g>\
</svg>\
</span>\
</a>\
<a href="javascript:;" class="btn btn-sm btn-clean btn-icon" title="Delete">\
<span class="svg-icon svg-icon-md">\
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="24px" height="24px" viewBox="0 0 24 24" version="1.1">\
<g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">\
<rect x="0" y="0" width="24" height="24"/>\
<path d="M6,8 L6,20.5 C6,21.3284271 6.67157288,22 7.5,22 L16.5,22 C17.3284271,22 18,21.3284271 18,20.5 L18,8 L6,8 Z" fill="#000000" fill-rule="nonzero"/>\
<path d="M14,4.5 L14,4 C14,3.44771525 13.5522847,3 13,3 L11,3 C10.4477153,3 10,3.44771525 10,4 L10,4.5 L5.5,4.5 C5.22385763,4.5 5,4.72385763 5,5 L5,5.5 C5,5.77614237 5.22385763,6 5.5,6 L18.5,6 C18.7761424,6 19,5.77614237 19,5.5 L19,5 C19,4.72385763 18.7761424,4.5 18.5,4.5 L14,4.5 Z" fill="#000000" opacity="0.3"/>\
</g>\
</svg>\
</span>\
</a>\
'
},
]
});
};
return {
init: function () {
initTableCat();
}
};
}();
jQuery(document).ready(function () {
DatatablesBasic.init();
});
I'm getting
this so I'm not sure what to do now. There's no error detected in the console. No pop up message by Datatable telling me there's something wrong. I tried the Datatable Debugger, no issues were detected
Data source: Javascript
Processing mode: Client-side
Draws: 1
Columns: 6
Rows - total: 2
Rows - after search: 2
Display start: 0
Display length: 10
I created a fiddle with all the code and it works
https://jsfiddle.net/q6L7g4ro/1/
just not in my application. I don't understand why
Related
I have an SVG hex map that I've joined to my dataset using a foreach function.
Dataset:
var data = [
{ "id": "Scotland ", "value": 5000 },
{ "id": "Wales ", "value": 3000 },
{ "id": "Ireland ", "value": 750 },
{ "id": "North West ", "value": 1250 },
{ "id": "North East ", "value": 4500 },
{ "id": "East Midlands ", "value": 2000 },
{ "id": "South East ", "value": 350 },
{ "id": "South West ", "value": 6000 },
{ "id": "East of England ", "value": 4000 },
{ "id": "West Midlands ", "value": 2500 },
{ "id": "Northern Ireland ", "value": 1000},
{ "id": "Isle of Man ", "value": 3000 },
{ "id": "Yorkshire and the Humber ", "value": 1500 },
{ "id": "Greater London ", "value": 5000 }
];
SVG Sample:
<g role="menuitem" aria-label="South East " transform="translate(445.5384524232801,-18.74937119481314)" cursor="pointer">
<path cs="100,100" d="M5.5,3.5 L0.5,6.5 L-4.5,3.5 L-4.5,-2.5 L0.5,-5.5 L5.5,-2.5 Z" fill="#ffffff" stroke="#ffffff" fill-opacity="1" stroke-width="0.01" stroke-opacity="1" transform="translate(0,0) scale(1)" class="amcharts-map-image"></path>
</g>
<g role="menuitem" aria-label="South East " transform="translate(409.5336486154187,-18.74937119481314)" cursor="pointer">
<path cs="100,100" d="M5.5,3.5 L0.5,6.5 L-4.5,3.5 L-4.5,-2.5 L0.5,-5.5 L5.5,-2.5 Z" fill="#ffffff" stroke="#ffffff" fill-opacity="1" stroke-width="0.01" stroke-opacity="1" transform="translate(0,0) scale(1)" class="amcharts-map-image"></path>
</g>
<g role="menuitem" aria-label="Greater London " transform="translate(457.534160443724,22.32951986709005)">
<path cs="100,100" d="M5.5,3.5 L0.5,6.5 L-4.5,3.5 L-4.5,-2.5 L0.5,-5.5 L5.5,-2.5 Z" fill="#ffffff" stroke="#ffffff" fill-opacity="1" stroke-width="0.01" stroke-opacity="1" transform="translate(0,0) scale(1)" class="amcharts-map-image"></path>
</g>
The function iterates through my dataset and maps the IDs to the respective IDs in the SVG. The IDs within the SVG are contained with the aria-label attribute of g (eg "Scotland", "South East", "Wales"...etc
Function
const ids = data.map(d => d.id);
ids.forEach(id =>
d3.selectAll(`g[aria-label="${id}"]`)
My data contains a Value against each ID/Region. What I'm trying to do is use a colour scale like this:
var colorScale = d3
.scaleLinear()
.domain(d3.extent(data, (d) => d.value))
.range(["#5C4D87", "#EC4E6B"])
.interpolate(d3.interpolateHcl)
...and apply that colour to my SVG based on the value assigned to the Region.
This is what I've tried so far:
const svgUrl = "https://raw.githubusercontent.com/gangrel11/samplefiles/main/amCharts.pixelMap.svg";
d3.xml(svgUrl).then(render);
function render(svg) {
d3.select("body").node().append(svg.documentElement)
const ids = data.map(d => d.id);
ids.forEach(id =>
d3.selectAll(`g[aria-label="${id}"]`)
.select('path')
.style("fill", function(d) {
return colorScale(d)
})
);
Iterate over your initial data not the map of ids.
data.forEach(d => {
d3.selectAll(`g[aria-label="${d.id}"]`)
.selectAll('path')
.style("fill",colorScale(d.value))
})
var dataTable = [{
id: '10',
date_create: '27-06-2019',
department_name: 'Отдел информационных систем',
status_name: 'В очереди на выполнение',
type_work_name: 'Не работает Интернет',
phone: '99-99-99',
auditory_name: 'В-200',
inventory_number: '24274',
comment: 'something goes wrong',
extra_fields: [{
"tw_value_field_id": "4",
"tw_field_value": "Microsoft Excel",
"type_work_name_field_id": "1",
"field_name": "Название программного обеспечения",
"field_datatype": "select",
"type_work_name_field_value": "Microsoft Word:Microsoft Word;Microsoft Excel:Microsoft Excel;Microsoft PowerPoint:Microsoft PowerPoint"
},
{
"tw_value_field_id": "5",
"tw_field_value": "Problem №1",
"type_work_name_field_id": "3",
"field_name": "Примечание",
"field_datatype": "textarea",
"type_work_name_field_value": null
},
{
"tw_value_field_id": "6",
"tw_field_value": "99-99-55",
"type_work_name_field_id": "2",
"field_name": "Телефон",
"field_datatype": "input",
"type_work_name_field_value": null
}
]
},
{
id: '20',
date_create: '28-06-2019',
department_name: 'Отдел информационных систем',
status_name: 'В очереди на выполнение',
type_work_name: 'Не работает Интернет',
phone: '99-99-98',
auditory_name: 'В-201',
inventory_number: '24275',
comment: 'something goes wrong',
extra_fields: [{
"tw_value_field_id": "7",
"tw_field_value": "Microsoft PowerPoint",
"type_work_name_field_id": "1",
"field_name": "Название программного обеспечения",
"field_datatype": "select",
"type_work_name_field_value": "Microsoft Word:Microsoft Word;Microsoft Excel:Microsoft Excel;Microsoft PowerPoint:Microsoft PowerPoint"
},
{
"tw_value_field_id": "8",
"tw_field_value": "Problem №2",
"type_work_name_field_id": "3",
"field_name": "Примечание",
"field_datatype": "textarea",
"type_work_name_field_value": null
},
{
"tw_value_field_id": "9",
"tw_field_value": "88-99-55",
"type_work_name_field_id": "2",
"field_name": "Телефон",
"field_datatype": "input",
"type_work_name_field_value": null
}
]
},
{
id: '30',
date_create: '20-06-2019',
department_name: 'Подготовительное отделение',
status_name: 'В очереди на выполнение',
type_work_name: 'Переустановка ОС',
phone: '99-99-00',
auditory_name: 'В-202',
inventory_number: '24276',
comment: 'something goes wrong',
extra_fields: [{
"tw_value_field_id": "10",
"tw_field_value": "Microsoft Word",
"type_work_name_field_id": "1",
"field_name": "Название программного обеспечения",
"field_datatype": "select",
"type_work_name_field_value": "Microsoft Word:Microsoft Word;Microsoft Excel:Microsoft Excel;Microsoft PowerPoint:Microsoft PowerPoint"
},
{
"tw_value_field_id": "11",
"tw_field_value": "Problem №3",
"type_work_name_field_id": "3",
"field_name": "Примечание",
"field_datatype": "textarea",
"type_work_name_field_value": null
},
{
"tw_value_field_id": "12",
"tw_field_value": "77-99-55",
"type_work_name_field_id": "2",
"field_name": "Телефон",
"field_datatype": "input",
"type_work_name_field_value": null
}
]
}
];
$(document).ready(function () {
$("#table-application").jqGrid({
datatype: "local",
data: dataTable,
colNames: ["Номер заявки в системе", "Дата создания", "Отдел", "Статус",
"Тип работ", "Номер телефона для связи", "Аудитория", "Инвентарный номер",
"Описание проблемы", ""
],
colModel: [{
name: "id",
id: "id"
},
{
name: "date_create",
id: "date_create"
},
{
name: "department_name",
id: "department_name",
},
{
name: "status_name",
id: "status_name",
editable: true,
edittype: "select",
editoptions: {
value: "1:В очереди на выполнение;2:Принята в работу;3:Закрыта"
}
},
{
name: "type_work_name",
id: "type_work_name",
editable: true,
edittype: "select",
editoptions: {
value: "1:Установка телефона; 2:Переустановка ОС; 3:Ремонт ПК и техники; 4:Заправка/замена картриджа; 5:Не работает Интернет"
}
},
{
name: "phone",
id: "phone",
editable: true
},
{
name: "auditory_name",
id: "auditory_name",
editable: true,
edittype: "select",
editoptions: {
value: "1:В-200; 2:В-201; 3:В-202; 4:K-300"
}
},
{
name: "inventory_number",
id: "inventory_number",
editable: true,
edittype: "select",
editoptions: {
value: "1:876547; 2:453213; 3:342123; 4:567496; 5:409325; 6:24274; 7:24275; 8:24276",
dataInit: function (el) {
$(el).select2({
language: 'ru',
width: '100%'
});
}
}
},
{
name: "comment",
id: "comment",
editable: true,
edittype: "textarea"
},
{
name: "extra_fields",
id: "extra_fields",
classes: "extra-field",
hidden: true,
title: false,
editable: false,
jsonmap: "extra_fields",
formatter: function (cellvalue) {
if (cellvalue != null) {
return JSON.stringify(cellvalue);
} else
return cellvalue;
}
}
],
pager: "#pager",
height: "auto",
autowidth: true,
forceFit: true,
sortorder: "desc",
viewrecords: true,
gridview: true,
autoencode: true,
caption: "Список заявок",
rownumbers: true,
subGrid: true,
subGridBeforeExpand: function (pID, id) {
//получаем значение поля extra_fields по id выбранной строки
extra_field_val = $('#table-application').jqGrid('getCell', id, 'extra_fields');
var jsonArray = $.parseJSON(extra_field_val);
//если дополнительная информация по заявке есть, раскрываем список
if (jsonArray.length > 0) {
console.log(true);
return true;
}
return false;
},
subGridRowExpanded: function (subgrid_id, row_id) {
var subgrid_table_id;
subgrid_table_id = subgrid_id + "_t";
jQuery("#" + subgrid_id).html("<table id='" + subgrid_table_id +
"' class='scroll'></table>");
extra_field_val = $('#table-application').jqGrid('getCell', row_id,
'extra_fields');
var response = $.parseJSON(extra_field_val);
//задаем массив для подтаблицы
var element_name, element_mode, col_name, objData;
var subColNames, subColModel, subData, selectValue;
subColNames = [];
subColModel = [];
subData = [];
objData = {};
for (var i = 0; i < response.length; i++) {
element_name = {};
element_name = response[i]['field_name'];
subColNames.push(element_name);
element_mode = {};
element_mode = {
name: "col_" + response[i]['tw_value_field_id'],
id: "col_" + response[i]['tw_value_field_id'],
editable: true
};
subColModel.push(element_mode);
if (response[i]['field_datatype'] == 'select') {
element_mode['edittype'] = "select";
selectValue = response[i]['type_work_name_field_value'];
element_mode['editoptions'] = {
value: selectValue
};
}
col_name = "col_" + response[i]['tw_value_field_id'];
objData[col_name] = response[i]['tw_field_value'];
}
subColNames.push("");
subColModel.push({
name: "id",
id: "id",
hidden: true,
editable: true,
editrules: {
edithidden: false
}
});
console.log(subColModel);
objData['id'] = response[0]['id'];
subData.push(objData);
var lastSel;
jQuery("#" + subgrid_table_id).jqGrid({
datatype: "local",
data: subData,
colNames: subColNames,
colModel: subColModel,
height: '75%',
caption: "Дополнительная информация",
onSelectRow: function (id) {
if (id && id !== lastSel) {
jQuery("#" + subgrid_table_id).restoreRow(lastSel);
lastSel = id;
}
jQuery("#" + subgrid_table_id).editRow(id, true);
},
editurl: 'clientArray'
});
},
editurl: 'clientArray'
});
$("#table-application").navGrid("#pager", {
edit: true,
add: false,
del: false,
search: false,
refresh: false,
editicon: "none",
edittext: "Редактировать",
}, {
/*hier setting of edit form*/
});
});
.ui-jqgrid {
font-size: 12px;
}
table {
table-layout: fixed;
}
table th,
table td {
word-wrap: break-word;
}
.table-light tbody+tbody,
.table-light td,
.table-light th,
.table-light thead th {
border-color: #b8c3c3;
}
th.ui-th-column div {
white-space: normal !important;
height: auto !important;
padding: 2px;
}
.ui-jqdialog-content .FormGrid {
margin: 0;
overflow: inherit;
}
.ui-jqdialog .ui-jqdialog-titlebar {
height: 30px;
}
.fm-button {
height: auto;
}
.ui-jqgrid .ui-jqgrid-titlebar {
height: 25px;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>jqGrid Edit Rows Example</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.10/css/select2.min.css" rel="stylesheet"/>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.css">
<link rel="stylesheet" href=" https://js.kintone.com/jqgrid/v5.4.0/css/ui.jqgrid.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.10/js/select2.min.js"></script>
<script src="https://js.kintone.com/jqgrid/v5.4.0/js/i18n/grid.locale-ru.js"></script>
<script src="https://js.kintone.com/jqgrid/v5.4.0/js/jquery.jqGrid.min.js"></script>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-12">
<div id="grid_container" class="mt-5">
<table id="table-application">
<tr>
<td></td>
</tr>
</table>
<div id="pager"></div>
</div>
</div>
</div>
</div>
</body>
</html>
I use together jqGrid and select2. In edition mode, when navigation rows, values from row is not substituted in select. If I click button with arrow "next" or "previous" value of inputs, textarea are changed but value of select are not changed.
This happens if I use select2, without select2 it works right. How can I fix it go on using select2?
setting select2 is below
{name: "status_name", id: "status_name", editable: true, edittype: "select", editoptions: {
dataUrl:"/Operator/OperatorApplicationController/getSelect&table=status",
dataInit: function (el) {
$(el).select2({
language: 'ru',
width: '100%'
});
}}}
Since the select2 is external plugin used in jqGrid, maybe you will need to refresh its value when the prev/next button is click.
I have never try this, but you can use the afterclickPgButtons for the form edit button click event - see docs here and undocumented change event in select2 - see here
This can look like this
$('#grid'). jqGrid('navGrid', pager, {params},
...
{ afterclickPgButtons : function(button, form, id ) {
$("#status_name").val(null).trigger('change.select2');
},...
} // edit options parameter
);
Mybe you will need to check if the id of the element is correct.
I am using amCharts stock chart to show trades within a period of time. I am using php and ajax to get values.
Now I do have period selector as buttons but I need them as a select. When a user selects a value from dropdown, the chart zoom should change accordingly. Is it possible to do that?
Below is my code to get a stock chart. Please help.
<div id="chartdiv" style="width:100%; height:400px;"></div>
<select id="mySelect" onchange="test()">
<option value="5">5
<option value="15">15
<option value="30">30
<option value="60">1H
<option value="D">1D
</select>
<script type="text/javascript">
AmCharts.addInitHandler(function (chart) {
}, ["stock"]);
var chartData = generateChartData();
console.log(chartData);
var chart = AmCharts.makeChart("chartdiv", {
"type": "stock",
"theme": "light",
"autoMarginOffset": 30,
"valueAxesSettings": {
"position": "right",
"inside": false,
"autoMargins": true,
"axisColor": "#000000",
"tickLength": 1
},
"categoryAxesSettings": {
"parseDates": true,
"minPeriod": "ss",
"axisColor": "#000000",
"tickLength": 1
},
"mouseWheelZoomEnabled": true,
"dataSets": [{
"fieldMappings": [{
"fromField": "open",
"toField": "open"
}, {
"fromField": "close",
"toField": "close"
}, {
"fromField": "high",
"toField": "high"
}, {
"fromField": "low",
"toField": "low"
}, {
"fromField": "volume",
"toField": "volume"
}],
"color": "#7f8da9",
"dataProvider": chartData,
"title": '<?php echo $symbol; ?>',
"categoryField": "date"
}
],
"panels": [{
"urlTarget": "_blank",
"showCategoryAxis": true,
"percentHeight": 70,
"valueAxes": [{
"dashLength": 5
}],
"categoryAxis": {
"dashLength": 5
},
"stockGraphs": [{
"id": "g1",
"type": "candlestick",
"proCandlesticks": false,
"balloonText": "Open:<b>[[open]]</b><br>Low:<b>[[low]]</b><br>High:<b>[[high]]</b><br>Close:<b>[[close]]</b><br>",
"openField": "open",
"closeField": "close",
"highField": "high",
"lowField": "low",
"lineAlpha": 1,
"lineColor": "#53b987",
"fillColors": "#53b987",
"fillAlphas": 0.9,
"negativeFillColors": "#eb4d5c",
"negativeLineColor": "#eb4d5c",
"useDataSetColors": false,
"title": "Volume:",
"valueField": "volume"
}],
"stockLegend": {
"valueTextRegular": undefined,
"periodValueTextComparing": "[[percents.value.close]]%"
}
}
],
"chartScrollbarSettings": {
"updateOnReleaseOnly": true,
"autoGridCount": true,
"graph": "g1",
"graphType": "line",
"scrollbarHeight": 30
},
"periodSelector": {
"position": "top",
"inputFieldsEnabled": false,
"periodsText": "",
"dateFormat": "YYYY-MM-DD JJ:NN",
"periods": [{
"period": "hh",
"count": 1,
"label": "5",
"selected": true
}, {
"period": "hh",
"count": 6,
"label": "15"
}, {
"period": "hh",
"count": 4,
"label": "30"
}, {
"period": "hh",
"count": 12,
"label": "1H"
}, {
"period": "dd",
"count": 60,
"label": "1D"
}]
},
"listeners": [
{
"event": "rendered",
"method": function (e) {
if (e.chart.ignoreResize) {
e.chart.ignoreResize = false;
return;
}
// init
var margins = {
"left": 0,
"right": 0
};
// iterate thorugh all of the panels
for (var p = 0; p < chart.panels.length; p++) {
var panel = chart.panels[p];
// iterate through all of the axis
for (var i = 0; i < panel.valueAxes.length; i++) {
var axis = panel.valueAxes[i];
if (axis.inside !== false) {
continue;
}
var axisWidth = axis.getBBox().width + 10;
if (axisWidth > margins[axis.position]) {
margins[axis.position] = axisWidth;
}
}
}
// set margins
if (margins.left || margins.right) {
chart.panelsSettings.marginLeft = margins.left;
chart.panelsSettings.marginRight = margins.right;
e.chart.ignoreResize = true;
chart.invalidateSize();
}
}
},
{
"event": "zoomed",
"method": function (e) {
e.chart.lastZoomed = e;
//console.log(e);
console.log("ignoring zoomed");
}
},
]
});
setInterval(function () {
//Setting the new data to the graph
chart.dataProvider = generateChartData();
chart.validateData();
}, 10000);
function test() {
var resolution = $("#mySelect").val();
//console.log(resolution);
var pp, count;
if (resolution == "D") {
resolution = "1D";
pp = 'dd';
count = 60;
}
else if (resolution == "60") {
resolution = "1H";
pp = 'hh';
count = 12;
}
else if (resolution == "30") {
pp = 'hh';
count = 4;
}
else if (resolution == "15") {
pp = 'hh';
count = 6;
}
else if (resolution == "5") {
pp = 'hh';
count = 1;
}
else {
pp = 'hh';
}
//console.log(pp);
for (var x in chart.periodSelector.periods) {
var period = chart.periodSelector.periods[x];
if (pp == period.period && resolution == period.count) {
period.selected = true;
}
else {
period.selected = false;
}
}
// console.log(period.period);
chart.periodSelector.setDefaultPeriod();
}
</script>
My previous issue was to get json data attached to amcharts, after struggling for a while, I got it running the way I want. But when I move it from test page to page where it would be listed with other charts it doesn't seem to work. When I click on blank chart this error appears in the console
Uncaught TypeError: Cannot read property 'length' of undefined
at Object.xToIndex (serial.js:14)
at b.handleCursorMove (serial.js:8)
at Object.a.inherits.b.fire (amcharts.js:1)
at Object.dispatchMovedEvent (amcharts.js:27)
at Object.handleMouseDown (amcharts.js:26)
at b.handleMouseDown (serial.js:1)
at HTMLDivElement.<anonymous> (amcharts.js:18)
Below is the code which is working when I have it on separate page
var chart = AmCharts.makeChart("chart1", {
"type": "serial",
"dataLoader": {
"url": "#myURL"
},
"valueAxes": [{
"title": "Load Average",
"gridColor": "#FFFFFF",
"gridAlpha": 0.2,
"dashLength": 0
}],
"gridAboveGraphs": true,
"startDuration": 1,
"graphs": [{
"balloonText": "[[title]] of [[category]]:[[value]]",
"id": "AmGraph-1",
"lineThickness": 3,
"valueField": "LoadAverage"
}],
"chartCursor": {
"categoryBalloonEnabled": false,
"cursorAlpha": 0,
"zoomable": false
},
"categoryField": "EndTimeLoop",
"categoryAxis": {
"title": "End Time Loop",
"gridPosition": "start",
"gridAlpha": 0,
"tickPosition": "start",
"tickLength": 20,
"labelRotation": 90
}
});
function setDataSet(dataset_url) {
AmCharts.loadFile(dataset_url, {}, function(data) {
chart.dataProvider = AmCharts.parseJSON(data);
chart.validateData();
});
};
this is the part where select happens in html side
<div class="chartWrapper" id="chartSingleTest1">
<select onchange="showChart(this.options[this.selectedIndex].value);">
<option value="chart1">Chart #1</option>
<option value="chart2">Chart #2</option>
<option value="chart3">Chart #3</option>
</select>
<div id="chart1" class="chartBoxSingle" style="display: none;"></div>
<div id="chart2" class="chartBoxSingle" style="display: none;"></div>
<div id="chart3" class="chartBoxSingle" style="display: none;"></div>
</div>
and here is js part where selects the first option on page load
var currentChart;
function showChart( divid ) {
if (currentChart !== undefined)
currentChart.style.display = "none";
if ( divid ) {
currentChart = document.getElementById(divid);
currentChart.style.display = "block";
}
else {
currentChart = undefined;
}
}
$(document).ready(function() { showChart('chart1'); });
You have to call the chart object's validateSize method when toggling the display of a chart from none to block as shown in this example that uses tabs. Here's another example using your structure:
var charts = {};
charts["chart1"] = AmCharts.makeChart("chart1", {
type: "serial",
dataProvider: [{
"value": 1,
"category": "Category 1"
}, {
"value": 2,
"category": "Category 2"
}, {
"value": 3,
"category": "Category 3"
}],
categoryField: "category",
graphs: [{
valueField: "value",
type: "column",
fillAlphas: .8
}]
});
charts["chart2"] = AmCharts.makeChart("chart2", {
type: "pie",
dataProvider: [{
"value": 2,
"title": "Slice 1"
}, {
"value": 2,
"title": "Slice 2"
}, {
"value": 2,
"category": "Slice 3"
}],
titleField: "title",
valueField: "value"
});
var currentChart;
function showChart(divid) {
if (currentChart !== undefined)
currentChart.style.display = "none";
if (divid) {
currentChart = document.getElementById(divid);
currentChart.style.display = "block";
charts[divid].validateSize();
} else {
currentChart = undefined;
}
}
$(document).ready(function() {
showChart('chart1');
});
.chartBoxSingle {
width: 100%;
height: 400px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript" src="//www.amcharts.com/lib/3/amcharts.js"></script>
<script type="text/javascript" src="//www.amcharts.com/lib/3/serial.js"></script>
<script type="text/javascript" src="//www.amcharts.com/lib/3/pie.js"></script>
<div class="chartWrapper" id="chartSingleTest1">
<select onchange="showChart(this.options[this.selectedIndex].value);">
<option value="chart1">Chart #1</option>
<option value="chart2">Chart #2</option>
</select>
<div id="chart1" class="chartBoxSingle" style="display: none;"></div>
<div id="chart2" class="chartBoxSingle" style="display: none;"></div>
</div>
I have set up a demo on this page : http://permanaj.net/jqgrid/index.html
code:
<html>
<head>
<title>JqGrid</title>
<link rel="stylesheet" type="text/css" href="smoothness/jquery-ui-1.8.16.custom.css" />
<link href="jqgrid/ui.jqgrid.css" type="text/css" rel="stylesheet" />
<script src="jquery-1.6.4.min.js" type="text/javascript"></script>
<script src="jquery-ui-1.8.16.custom.min.js" type="text/javascript"></script>
<script type="text/javascript" src="jqgrid/i18n/grid.locale-en.js"></script>
<script type="text/javascript" src="jqgrid/jquery.jqGrid.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
/* test save cart */
$('#test-save').click(function(){
var qtyOrder = new Array(), tmpVal, tmpKdProd;
$('.qty-order').each(function(k, v){
tmpVal = $(v).val();
tmpKdProd = '';
if (tmpVal > 0) {
tmpKdProd = $(v).attr('title');
qtyOrder.push( tmpKdProd+'='+tmpVal);
}
});
console.log('Recap Order : ' + qtyOrder.join(','));
return false;
});
/* jqgrid */
function qadQuantityFormatter(cellvalue, options, rowObject){
return '<input type="text" class="qty-order" value="'+cellvalue+'" class="text" title="'+rowObject[3]+'" id="qty-'+rowObject[3]+'"/>';
}
$.jgrid.no_legacy_api = true;
$.jgrid.useJSON = true;
$('#the-grid').jqGrid({
url: 'data.json',
datatype: 'json',
mtype: 'GET',
colNames: ['Produk Line', 'Produk Group', 'Satuan Ukuran', 'Kode Produk', 'Nama Produk', 'Harga', 'Order Qty.'],
colModel: [
{name:'NAMA_PRODUK_LINE', index: 'NAMA_PRODUK_LINE', width:200, jsonmap: 'cell.NAMA_PRODUK_LINE'},
{name:'NAMA_PRODUK_GROUP', index: 'NAMA_PRODUK_GROUP', width:200, jsonmap: 'cell.NAMA_PRODUK_GROUP'},
{name:'SATUAN', index: 'SATUAN', width:200, jsonmap: 'cell.SATUAN'},
{name:'KODE_PRODUK', index: 'KODE_PRODUK', width:200, jsonmap: 'cell.KODE_PRODUK'},
{name:'NAMA_PRODUK', index: 'NAMA_PRODUK', width:200, jsonmap: 'cell.NAMA_PRODUK'},
{name:'HARGA', index: 'HARGA', width:200, jsonmap: 'cell.HARGA'},
{name:'order', index: 'order', width:200, jsonmap: 'cell.order', formatter: qadQuantityFormatter}
],
rowNum: 10,
rowList: [10, 20, 30],
pager: '#the-grid-pager',
sortname: 'NAMA_PRODUK_LINE',
sortorder: 'ASC',
caption: 'Daftar Produk',
viewrecords: true,
loadonce: true,
height: 250,
autowidth: true,
onPaging : function(but) {
//alert("Button: "+but + " is clicked");
}
});
$('#the-grid').jqGrid('navGrid','#the-grid-pager',{edit:false,add:false,del:false});
/* cart quantity */
$('#the-grid').delegate('.qty-order', 'blur', function(){
console.log('Order Quantity : ' + $(this).val());
});
});
</script>
</head>
<body>
<div id="wrapper">
<table id="the-grid"></table>
<div id="the-grid-pager"></div>
</div>
</body>
json data:
{
"page":1,
"total":38,
"records":375,
"rows":[
{
"id":"MA0201001",
"cell":[
"Additives",
"MA02",
"KILOGRAM",
"MA0201001",
"Hal Color Black HC 969.50",
"0.00",
0
]
},
{
"id":"MA0202002",
"cell":[
"Additives",
"MA02",
"KILOGRAM",
"MA0202002",
"CaCO3 BAP-800 Bukit Ashar",
"0.00",
0
]
},
{
"id":"MA0202004",
"cell":[
"Additives",
"MA02",
"KILOGRAM",
"MA0202004",
"CaCo3 OM 1 TGD",
"0.00",
0
]
},
{
"id":"MA0204001",
"cell":[
"Additives",
"MA02",
"KILOGRAM",
"MA0204001",
"Stab CRC Power ex Taiwan",
"0.00",
0
]
},
{
"id":"MA0205001",
"cell":[
"Additives",
"MA02",
"KILOGRAM",
"MA0205001",
"Dioxtyl Ptalate Oil",
"0.00",
0
]
},
{
"id":"MA0206002",
"cell":[
"Additives",
"MA02",
"KILOGRAM",
"MA0206002",
"PX 105 ex Malaysia",
"0.00",
0
]
},
{
"id":"MA0206026",
"cell":[
"Additives",
"MA02",
"KILOGRAM",
"MA0206026",
"Rikemal AS-005 ex Malaysia",
"0.00",
0
]
},
{
"id":"MA0208003",
"cell":[
"Additives",
"MA02",
"KILOGRAM",
"MA0208003",
"Tribasic Chemson Naftovin T3A ex China",
"0.00",
0
]
},
{
"id":"MA0208004",
"cell":[
"Additives",
"MA02",
"KILOGRAM",
"MA0208004",
"Naftomix GRD 19043-I Chemson ex China",
"0.00",
0
]
},
{
"id":"MA0208005",
"cell":[
"Additives",
"MA02",
"KILOGRAM",
"MA0208005",
"Tribasic Naftovin T3 Chemson ex UK",
"0.00",
0
]
},
{
"id":"MA0208006",
"cell":[
"Additives",
"MA02",
"KILOGRAM",
"MA0208006",
"Naftomix PRD 2088 Chemson RRC",
"0.00",
0
]
},
...
{
"id":"MA0103003",
"cell":[
"Resin",
"MA01",
"KILOGRAM",
"MA0103003",
"PVC Resin K-65 ST",
"0.00",
0
]
}
]
}
For example, I change the number of Order Qty to 20 for all items, when I click Next once and then click Back once, the number on textfield is reset to 0, not 20
How to achieve when page change, the number on textfield is still 20
Since the quantity field is populated from the remote ajax data,
I think you can only use the onPaging event to save the changes at server side first before the page changes.
Probably using the saveRow method offered.