Chartjs2 Legend Not working - ajax

I'm trying to plot a lineal graphic that gets data from ajax using Chartjs 2.5.
This is the main function for this procedure. The main problem is that the legend doesn't appear.
function initDigitalValueChart(divName, ids) {
if ($(divName)) {
/*for (var j=0; j<ids.length; j++) {
console.log(j);
datasetValue[j] = {
fillColor: 'rgba(220,220,220,0.5)',
strokeColor :'rgba(220,220,220,1)',
title :'2013',
data : [Math.round(Math.random() * 1),Math.round(Math.random() * 1)]
}
}*/
var datasetValue = [];
var calls = [];
for (var j = 0; j < ids.length; j++) {
var labels = []
URL = "*****" + ids[j];
calls.push($.getJSON(URL, function(response) {
var values = []
if (response != null) {
$.each(response, function(index, data) {
labels.push(data["timestamp"]);
values.push(data["value"]);
title = data["sensorName"]
});
datasetValue.push({
label: title,
lineTension: 0,
borderColor: "rgba(" + Math.floor(Math.random() * 255) + ", " + Math.floor(Math.random() * 255) + ", " + Math.floor(Math.random() * 255) + ", 0.70)",
backgroundColor: "transparent",
data: values,
radius: 0,
pointHitRadius: 0,
steppedLine: true,
});
}
}))
}
$.when.apply($, calls).then(function() {
var ctx = document.getElementById('digital').getContext("2d");
var lineChart = new Chart(ctx, {
type: 'line',
data: {
labels: labels,
datasets: datasetValue
},
options: {
legend: {
display: true,
labels: {
fontColor: "white",
fontSize: 18
}
},
scales: {
xAxes: [{
display: true,
scaleLabel: {
display: true,
labelString: 'Data Hora'
}
}],
yAxes: [{
display: true,
scaleLabel: {
display: true,
labelString: 'Valor'
}
}]
}
}
});
//document.getElementById('digital-legend').innerHTML = lineChart.generateLegend();
});
}
}
I tried to add the position: 'top' option but in this case the console returns
Uncaught TypeError: Cannot read property 'call' of undefined
Has anyone else had problems with this?

Related

Feeding highchart with x and y values from ajax

I'm trying to feed my highchart from a database using ajax. From my ajax request, I want to return both x and y values (the x value is like that: year-week, ie 2020-16; the y value is a random number). My chart remains blank, I have a silent error that I cannot figure out. I'm pretty sure it comes from the strucure of the data returned by ajax, but I can't seem to fix it on my own.
Here's my javascript:
var weekOptions = {
chart: {
renderTo: 'weekContainer',
type: 'column',
},
title: {
text: 'Last 52 weeks',
},
credits: {
enabled: false,
},
xAxis: {
lineWidth: .5,
tickWidth: 1,
tickLength: 10,
},
yAxis: {
title: {
text: 'Distance (miles)'
},
labels: {
formatter: function() {
return this.value;
},
},
allowDecimals: false,
gridLineWidth: 1,
},
tooltip: {
crosshairs: true,
split: true,
useHTML: true,
valueDecimals: 2,
valueSuffix: ' miles',
formatter: '',
},
plotOptions: {
spline: {
marker: {
symbol: "circle",
radius: 3,
}
}
},
lang: {
noData: "No Data. Make sure at least one activity type is selected."
},
noData: {
style: {
fontWeight: 'bold',
fontSize: '15px',
color: '#303030'
}
},
exporting: {
buttons: {
contextButton: {
menuItems: ['viewFullscreen']
}
},
},
series: [{}],
};
//get series from ajax filtered by activity types
$.ajax({
url: "weekGetSeries.php",
type: "POST",
data: {
activityType: activityTypeSelected,
dataToDisplay: dataToDisplay,
},
dataType: "JSON",
success: function (json) {
weekOptions.series = json;
var chart = new Highcharts.Chart(weekOptions);
}
});
And here my ajax php file:
<?php
require 'dbConnection.php';
$activityType = array(1,2,3,4,5);
$dataToDisplay = "distance";
$startingDate = date('Y-m-d', strtotime('-52 week', time()));
$firstWeek = strtotime($startingDate);
$conditionActivityType = ' WHERE startingTime >= "' . $startingDate . '" AND (type=' . implode(" OR type=",$activityType) . ')';
$dataSerie = array("name" => "Weekly Stats","data" => array());
for($i = 0; $i < 52; $i++){
$nextWeek = strtotime('+'.$i.' week', $firstWeek);
$dataSerie["data"][date("o",$nextWeek) . "-" . date("W",$nextWeek)] = 0;
}
$getActivities = $conn->query("SELECT * FROM activity" . $conditionActivityType . " ORDER BY startingTime ASC");
if ($getActivities->num_rows > 0) {
while($row = $getActivities->fetch_assoc()) {
$date = substr($row["startingTime"],0,10);
$date = strtotime($date);
$week = date("W",$date);
$category = date("Y-",$date).$week;
$distance = ($row["distance"]);
$movingTime = $row["movingTime"];
$elapsedTime = $row["elapsedTime"];
$totalElevationGain = ($row["totalElevationGain"])*3.28084;
switch ($dataToDisplay) {
//distance
case "distance":
$dataSerie["data"][$category] += $distance;
break;
//Moving Time
case "movingTime":
break;
//Elapsed Time
case "elapsedTime":
break;
//elevation gain
case "totalElevationGain":
break;
//number activities
case "activities":
break;
}
}
};
$data = array();
array_push($data,$dataSerie);
echo json_encode($data);
?>
My ajax returns this:
[{"name":"Weekly Stats","data":{"2019-17":13184.4,"2019-18":73560.2,"2019-19":36899.4,"2019-20":0,"2019-21":38691.3,"2019-22":165127.8,"2019-23":188163.2,"2019-24":12888.5,"2019-25":60011.3,"2019-26":32585.2,"2019-27":12952.8,"2019-28":7944.8,"2019-29":79258.3,"2019-30":60885.2,"2019-31":0,"2019-32":0,"2019-33":0,"2019-34":0,"2019-35":0,"2019-36":0,"2019-37":30974.6,"2019-38":7766.5,"2019-39":7685,"2019-40":21128.7,"2019-41":28996,"2019-42":46362.6,"2019-43":0,"2019-44":0,"2019-45":63694.8,"2019-46":81551.1,"2019-47":104595.9,"2019-48":18121.7,"2019-49":18691.6,"2019-50":37538,"2019-51":40671.8,"2019-52":22109.6,"2020-01":22079,"2020-02":22086.7,"2020-03":21933.2,"2020-04":30702.1,"2020-05":58259,"2020-06":38811.3,"2020-07":43754,"2020-08":45109.1,"2020-09":50870.1,"2020-10":62917.8,"2020-11":0,"2020-12":95912.5,"2020-13":20836.2,"2020-14":25293,"2020-15":110540.5,"2020-16":150804.9}}]
How do I structure my data so I can feed my chart?
In your case series.data needs to be an array of arrays or an array of objects. Now it is an object.
data: [
[0, 6],
[1, 2],
[2, 6]
]
Or:
data: [{
x: 1,
y: 9
}, {
x: 1,
y: 6
}]
Live demo: http://jsfiddle.net/BlackLabel/6m4e8x0y/4977/
API Reference: https://api.highcharts.com/highcharts/series.column.data

Plot two lines on same month with different dates with Base-unit :month

I am developing a chart on Kendo-UI, where we need to plot a vertical line w.r.t dates available on the x-axis. The challenge, that I am facing is my x-axis contains BaseUnit: months. when I am plotting bands w.r.t two different dates in the same month, the system generates vertical line but captures a complete month section rather than plotting two different lines in the same month.
Sample Code:
var DateRange = [];
var PlotData = [];
var AllData = [];
function BindDates() {
for (var startmonth = 01; startmonth <= 12; startmonth++) {
for (var startday = 01; startday <= 30; startday++) {
DateRange.push(new Date("2019/" + startmonth + "/" + startday));
AllData.push(Math.floor((Math.random() * startday) * new Date().getMilliseconds()));
}
for (var Initial = 1; Initial <= 3; Initial++) {
var data = null;
if (Initial == 1) {
data = { from: new Date("2019/02/03"), to: new Date("2019/02/03"), color: "red", width: 0.1 };
}
else if (Initial == 2) {
data = { from: new Date("2019/05/03"), to: new Date("2019/05/03"), color: "green", width: 0.1 };
}
else if (Initial == 3) {
data = { from: new Date("2019/06/03"), to: new Date("2019/06/03"), color: "black", width: 0.1 };
}
PlotData.push(data);
}
}
createChart(DateRange, AllData, PlotData);
}
function createChart(datesss, alldata, PlotData) {
$("#chart").kendoChart({
title: {
text: "Chart Title"
},
legend: {
position: "bottom"
},
seriesDefaults: {
type: "area",
area: {
line: {
style: "smooth"
}
}
},
series: [
{
name: "Late",
color: "orange",
data: alldata
}, {
type: "line",
dashType: "dashDot",
name: "Est DT",
color: "grey",
data: alldata
},
{
name: "On time",
color: "blue",
data: alldata
}],
valueAxis: {
labels: {
format: "{0}"
},
line: {
visible: false
},
axisCrossingValue: -10
},
categoryAxis: {
type: "date",
categories: datesss,
baseUnit: "months",
labels: {
dateFormats: {
months: "MMM-yy"
}
},
majorGridLines: {
visible: false
},
labels: {
rotation: "auto",
},
plotBands: PlotData
},
tooltip: {
visible: true,
format: "{0}%",
template: "#= series.name #: #= value #"
}
});
}
BindDates();
$(document).ready(function () {
BindDates();
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://kendo.cdn.telerik.com/2019.3.1023/js/kendo.all.min.js"></script>
<div id='chart'></div>

Jquery Selected Rows Value

I have a datatable. I want to retrieve the ID values of the rows that are selected.
How can I do that.
My codes:
var DatatableRecordSelectionDemo = function () {
var demo = function () {
var url = '/Data/default.json';
$.getJSON(url, function (data) {
var datatable = $('.m_datatable').mDatatable({
data: {
type: "local",
source: data,
pageSize: 10,
saveState: {
cookie: true,
webstorage: true
},
serverPaging: true,
serverFiltering: true,
serverSorting: true
},
// layout definition
layout: {
theme: 'default', // datatable theme
"class": '', // custom wrapper class
scroll: false, // enable/disable datatable scroll both horizontal and vertical when needed.
height: 550, // datatable's body's fixed height
footer: false // display/hide footer
},
// column sorting
sortable: true,
pagination: true,
// columns definition
columns: [{
field: "RecordID",
title: "#",
sortable: false, // disable sort for this column
width: 40,
textAlign: 'center',
selector: { class: 'm-checkbox--solid m-checkbox--brand' }
}, {
field: "OrderID",
title: "Numara",
// sortable: 'asc', // default sort
filterable: true, // disable or enable filtering
// basic templating support for column rendering,
template: '{{OrderID}} - {{ShipCountry}}'
}, {
field: "ShipName",
title: "Adı"
}, {
field: "Status",
title: "Durumu",
// callback function support for column rendering
template: function (row) {
var status = {
true: { 'title': 'Aktif', 'class': ' m-badge--success' },
false: { 'title': 'Pasif', 'class': ' m-badge--danger' }
};
return '<span class="m-badge ' + status[row.Status].class + ' m-badge--wide">' + status[row.Status].title + '</span>';
}
}, {
field: "Actions",
title: "İşlem",
width: 100,
sortable: false,
overflow: 'visible',
template: function (row) {
var tblName = String(row.ShipName).replace(/'/g, "\\'");
var tblid = String(row.RecordID);
return '\
<a href="#" onclick="Modalac('+ tblid + ',\'' + tblName + '\',' + row.Status + ')" class="m-portlet__nav-link btn m-btn m-btn--hover-accent m-btn--icon m-btn--icon-only m-btn--pill" title="Düzenle">\
<i class="la la-edit"></i>\
</a>\
<a href="#" onclick="Sil('+ tblid + ',\'' + tblName + '\')" class="m-portlet__nav-link btn m-btn m-btn--hover-danger m-btn--icon m-btn--icon-only m-btn--pill" title="Sil">\
<i class="la la-trash"></i>\
</a>\
';
}
}]
});
var query = datatable.getDataSourceQuery();
$('#m_form_search').on('keyup', function (e) {
// shortcode to datatable.getDataSourceParam('query');
var query = datatable.getDataSourceQuery();
query.generalSearch = $(this).val().toLowerCase();
// shortcode to datatable.setDataSourceParam('query', query);
datatable.setDataSourceQuery(query);
datatable.load();
}).val(query.generalSearch);
$('#m_form_status').on('change', function () {
// shortcode to datatable.getDataSourceParam('query');
var query = datatable.getDataSourceQuery();
query.Status = $(this).val().toLowerCase();
// shortcode to datatable.setDataSourceParam('query', query);
datatable.setDataSourceQuery(query);
datatable.load();
}).val(typeof query.Status !== 'undefined' ? query.Status : '');
$('#m_form_status').selectpicker();
// on checkbox checked event
$('.m_datatable').on('m-datatable--on-check', function (e, args) {
var count = datatable.setSelectedRecords().getSelectedRecords().length;
$('#m_datatable_selected_number').html(count);
if (count > 0) {
$('#m_datatable_group_action_form').collapse('show');
}
})
.on('m-datatable--on-uncheck m-datatable--on-layout-updated', function (e, args) {
var count = datatable.setSelectedRecords().getSelectedRecords().length;
$('#m_datatable_selected_number').html(count);
if (count === 0) {
$('#m_datatable_group_action_form').collapse('hide');
}
});
$('.m_datatable tbody').on('click', 'tr', function (){
var id = this.RecordID;
var index = $.inArray(id, selected);
if (index === -1)
{
selected.push(id);
} else
{
selected.splice(index, 1);
}
$(this).toggleClass('selected');
});
});
};
return {
// public functions
init: function () {
demo();
}
};
}();
var TopluIslem = function () {
var datatable = $('.m_datatable').mDatatable();
var dataArr = [];
$.each($(".m_datatable tr.selected"),function(){
dataArr.push($(this).find('td').eq(0).text());
});
console.log(dataArr);
alert(rowCount);
};
jQuery(document).ready(function () {
DatatableRecordSelectionDemo.init();
});
İşlem Yap
I solved the problem
var secilenler = [];
$('.m_datatable').on('m-datatable--on-check', function(e, args) {
secilenler.push(args.toString());
}).on('m-datatable--on-uncheck', function (e, args) {
var i = secilenler.indexOf(args.toString());
if(i !== -1) {
secilenler.splice(i, 1);
}
});

How to plot 500 points in a second in highchart?

We are supposed to plot 500 points every second from ajax request which we get it from WCF service(hosted in amazon cloud).
We are using highchart, but its very slow.
Is there any solution ? or any other graph control which we can use it in our case so that performnace is efficient
var chart = new Highcharts.Chart({
chart: {
type: 'spline',
animation: false,//Highcharts.svg, // don't animate in old IE
marginRight: 10,
renderTo: 'Chart',
events: {
load: function () {
}
}
},
title: {
text: 'Data'
},
xAxis: {
type: 'datetime',
tickPixelInterval: 150,
max: ((new Date()).getTime()) + 50 * 10000
},
yAxis: {
title: {
text: 'Data',
min: 50,
max: 500
},
plotLines: [{
value: 0,
width: 1,
color: '#FFFF00'
}]
},
plotOptions: {
line: {
marker: {
enabled: false
}
}
},
tooltip: {
},
legend: {
enabled: false
},
exporting: {
enabled: false
},
plotOptions: {
series: {
marker: {
enabled: false
}
}
},
series: [{
name: 'Chart',
color: '#335de8',
//data: []
data: (function () {
//generate an array of random data
var data = [];
var data = [],
time = (new Date()).getTime(), i;
for (i = 1; i <= 0; i++) {
data.push({
x: time + i * 1000,
y: null
});
}
return data;
})()
}]
});
chart.yAxis[0].setExtremes(-200, 500);
UpdateChart();
function UpdateChart() {
var Chrt = chart.series[0];
setInterval(function () {
$.ajax({
url: 'getChartData/',
cache: false,
type: "POST",
success: function (result) {
for (var tmpJ = 0; tmpJ < result.length; tmpJ++) {
Chrt.addPoint([(new Date()).getTime(), eval(result[tmpJ])], true, false);
Chrt.redraw(false);
}
});
}, 1000);
}
Try to replace this line
Chrt.addPoint([(new Date()).getTime(), eval(result[tmpJ])], true, false);
with
if(tmpJ==result.length-1){
Chrt.addPoint([(new Date()).getTime(), eval(result[tmpJ])], false, false);
} else {
Chrt.addPoint([(new Date()).getTime(), eval(result[tmpJ])], true, false);
}

Jq tree grid did not load the data from a controller

I am using a jqgrid and i want to display the grid from the jquery a call to controller which return me json data my grid did not show the data code is here
my controller action is like this
private static List<Category> GetProducts(int parent, int childs)
{
string[] procat = { "Electrical", "Computer", "Furniture", "House Hold", "Automobiles" };
var data = new List<Category>();
for (int i = 0; i < parent; i++)
{
data.Add(new Category { CatId = i, CatName = procat[i % 5], Products = new List<Product>() });
for (int j = 0; j < childs; j++)
{
data[i].Products.Add(new Product
{
ProId = j,
ProName = "ABC",
desc = "A web browser built for speed, simplicity, and security",
desc1 = "Google Chrome",
desc2 = (i * j).ToString(),
desc3 = "Copyright 2013 Google Inc. All rights reserved.",
desc4 = i.ToString(),
desc5 = j.ToString(),
desc6 = "Google Chrome",
desc7 = (i * j).ToString(),
desc8 = "Copyright 2013 Google Inc. All rights reserved.",
desc9 = i.ToString(),
desc10 = j.ToString(),
desc11 = "Google Chrome",
desc12 = (i * j).ToString(),
desc13 = "Copyright 2013 Google Inc. All rights reserved.",
desc14 = i.ToString(),
desc15 = j.ToString(),
desc16 = "Google Chrome",
desc17 = (i * j).ToString(),
desc18 = "Copyright 2013 Google Inc. All rights reserved.",
desc19 = i.ToString(),
desc20 = j.ToString(),
desc21 = "Google Chrome",
desc22 = (i * j).ToString(),
desc23 = "Copyright 2013 Google Inc. All rights reserved.",
desc24 = i.ToString(),
desc25 = j.ToString()
});
}
}
return data;
}
public JsonResult PlainObjectsView()
{
var res = new List<FlatProduct>();
string[] procat = { "Electrical", "Computer", "Furniture", "House Hold", "Automobiles" };
int i = 1;
foreach (var item in procat)
{
res.Add(new FlatProduct
{
CatId = i,
CatName = item,
ProName = item,
ProId = i,
level = 0,
parent =null,
Isleaf = false,
IsLoaded = true,
Isexpanded = true
});
i++;
}
var data = GetProducts(5, 5);
foreach (var cats in data)
{
foreach (var prods in cats.Products)
{
res.Add(new FlatProduct
{
CatId = cats.CatId + 1,
CatName = cats.CatName,
ProId = prods.ProId,
ProName = prods.ProName,
desc = prods.desc,
desc1 = prods.desc1,
desc2 = prods.desc2,
desc3 = prods.desc3,
desc4 = prods.desc4,
desc5 = prods.desc5,
desc6 = prods.desc6,
desc7 = prods.desc7,
desc8 = prods.desc8,
desc9 = prods.desc9,
desc10 = prods.desc10,
desc11 = prods.desc11,
desc12 = prods.desc12,
desc13 = prods.desc13,
desc14 = prods.desc14,
desc15 = prods.desc15,
desc16 = prods.desc16,
desc17 = prods.desc17,
desc18 = prods.desc18,
desc19 = prods.desc19,
desc20 = prods.desc20,
desc21 = prods.desc21,
desc22 = prods.desc22,
desc23 = prods.desc23,
desc24 = prods.desc24,
desc25 = prods.desc25,
level = 1,
parent = cats.CatId + 1,
Isleaf = false,
IsLoaded = true,
Isexpanded = true
});
}
}
double pagesize = 5;
var finalRes = new { page = 1, records = res.Count, rows = res, total = Math.Ceiling(res.Count / pagesize), id = res.Select(c=>c.CatId), };
return Json(finalRes, JsonRequestBehavior.AllowGet);
}
and my jquery is like this
<script type="text/javascript">
$(document).ready(function () {
'use strict';
$("#treegrid").jqGrid({
url: '#Url.Content("~/TreeGrid/PlainObjectsView")',
datatype: "json",
mtype: "Get",
colModel: [
{ name: "CatId", width: 150,key:true, hidden:true},
{ name: "CatName", width: 200 },
{ name: "desc", width: 200 },
{ name: "desc1", width: 300 },
{ name: "desc10", width: 300 },
{ name: "desc11", width: 150 },
{ name: "desc12", width: 200 },
{ name: "desc13", width: 300 },
{ name: "desc14", width: 150 },
{ name: "desc15", width: 200 },
{ name: "desc16", width: 300 },
{ name: "desc17", width: 150 },
{ name: "desc18", width: 200 },
{ name: "desc19", width: 300 },
{ name: "desc2", width: 150 },
{ name: "desc20", width: 150 },
{ name: "desc21", width: 200 },
{ name: "desc22", width: 300 },
{ name: "desc23", width: 150 },
{ name: "desc24", width: 200 },
{ name: "desc25", width: 300 },
{ name: "desc3", width: 200 },
{ name: "desc4", width: 300 },
{ name: "desc5", width: 150 },
{ name: "desc6", width: 200 },
{ name: "desc7", width: 300 },
{ name: "desc8", width: 150 },
{ name: "desc9", width: 200 },
{ name: "ProId", width: 300, hidden:true },
{ name: "ProName", width: 150 }
],
treeGridModel: 'adjacency',
height: "auto",
ExpandColumn: 'CatName',
// ExpandColClick: true,
loadonce:true,
treeGrid: true,
// gridview: true,
viewrecords: true,
caption: "Tree Grid Example"
});
});
</script>
help me please where is i m wrong
First of all we should ordered the data in specific json format first add parent and then add its children like this
public IEnumerable<FlatProduct> TreeGridjsonData()
{
var res = PlainObjectsViewNew();
int count = 1;
var list1 = (from rs in res
where rs.parent == null
select rs).ToList<FlatProduct>();
foreach (var item in list1)
{
finalList.Add(
new FlatProduct
{
Id = count,
CatId = item.CatId,
CatName = item.CatName,
level = 0,
parent = null,
Isleaf = false,
//IsLoaded = true,
Isexpanded = false
});
AddChildren(item.CatId, count);
count += 6;
}
return finalList;
}
public IEnumerable<FlatProduct> AddChildren(int parentid, int count)
{
int lscount = count + 1;
var res = PlainObjectsViewNew();
var list1 = from rs in res
where rs.parent == parentid
select rs;
foreach(var item in list1)
{
finalList.Add(new FlatProduct
{
CatName = item.CatName,
ProId = item.ProId,
ProName = item.ProName,
Id = lscount,
desc = item.desc,
desc1 = item.desc1,
desc2 = item.desc2,
desc3 = item.desc3,
desc4 = item.desc4,
desc5 = item.desc5,
desc6 = item.desc6,
desc7 = item.desc7,
desc8 = item.desc8,
desc9 = item.desc9,
desc10 = item.desc10,
desc11 = item.desc11,
desc12 = item.desc12,
desc13 = item.desc13,
desc14 = item.desc14,
desc15 = item.desc15,
desc16 = item.desc16,
desc17 = item.desc17,
desc18 = item.desc18,
desc19 = item.desc19,
desc20 = item.desc20,
desc21 = item.desc21,
desc22 = item.desc22,
desc23 = item.desc23,
desc24 = item.desc24,
desc25 = item.desc25,
level = 1,
parent = count,
Isleaf = true,
IsLoaded = true,
Isexpanded = true
});
lscount++;
}
return finalList;
}
After that convert this list into json format for this
public JsonResult GetPlainobject()
{
var rows = (PlainObjectsViewNew()
.Select(c => new
{
id=c.Id,
cell =new []
{
c.Id.ToString(),
c.CatName,
c.desc,
c.desc1,
c.desc10,
c.desc11,
c.desc12,
c.desc13,
c.desc14,
c.desc15,
c.desc16,
c.desc17,
c.desc18,
c.desc19,
c.desc2,
c.desc20,
c.desc21,
c.desc22,
c.desc23,
c.desc24,
c.desc25,
c.desc3,
c.desc4,
c.desc5,
c.desc6,
c.desc7,
c.desc8,
c.desc9,
c.ProId.ToString(),
c.ProName,
c.level.ToString(),
c.parent.ToString(),
c.Isexpanded.ToString(),
c.IsLoaded.ToString(),
c.Isleaf.ToString(),
}
})).ToArray();
return Json(new
{
page = 1,
records = rows.Length,
rows
}, JsonRequestBehavior.AllowGet);
}
And after that some change in the javascript function
$(document).ready(function () {
$("#treegrid").jqGrid({
url: '#Url.Content("~/TreeGrid/GetPlainobjectOrderdData")',
datatype: "json",
mtype: "Get",
colModel: [
{ name: "CatId", width: 150,key:true, hidden:true},
{ name: "CatName", width: 200 },
{ name: "desc", width: 200 },
{ name: "desc1", width: 300 },
{ name: "desc10", width: 300 },
{ name: "desc11", width: 150 },
{ name: "desc12", width: 200 },
{ name: "desc13", width: 300 },
{ name: "desc14", width: 150 },
{ name: "desc15", width: 200 },
{ name: "desc16", width: 300 },
{ name: "desc17", width: 150 },
{ name: "desc18", width: 200 },
{ name: "desc19", width: 300 },
{ name: "desc2", width: 150 },
{ name: "desc20", width: 150 },
{ name: "desc21", width: 200 },
{ name: "desc22", width: 300 },
{ name: "desc23", width: 150 },
{ name: "desc24", width: 200 },
{ name: "desc25", width: 300 },
{ name: "desc3", width: 200 },
{ name: "desc4", width: 300 },
{ name: "desc5", width: 150 },
{ name: "desc6", width: 200 },
{ name: "desc7", width: 300 },
{ name: "desc8", width: 150 },
{ name: "desc9", width: 200 },
{ name: "ProId", width: 300, hidden:true },
{ name: "ProName", width: 150 }
],
// gridComplete: doGridComplete,
onInitGrid: doOnInitGrid,
loadComplete: doloadComplete,
treeGridModel: 'adjacency',
height: "auto",
ExpandColumn: 'CatName',
//gridview: true,
loadonce:false,
treeGrid: true,
treedatatype:'jsonstring',
viewrecords: true,
treeIcons: { leaf: 'ui-icon-document-b' },
caption: "Tree Grid Example"
});
});
and this is done

Resources