JQGrid data from Local Object array - arrays

I create a local object collection based on the user's selection. The dynamic Array should be loaded to the jqGrid. After dynamically creating the array I tried to reload, but nothing happens. Here is the code -
$(document).ready(function () {
var arrobj = [];
var JSONString = []; //[{"DOId":"0","DONo":"Please select","DealerCode":"0","Week":"0","Item":"0","Qty":"11","Date":"11"}]
$("#<%=btnAdd.ClientID%>").click(function () {
//Get values
//Date
var dlDt = $("#<%=tbRchngDt.ClientID%>").val();
//Qty
var dlQty = $("#<%=tbQty.ClientID%>").val();
//item
var dlItem = $("#<%=ddlItem.ClientID%>").val();
//DO No
var dlDOId = $("#<%=ddlDO.ClientID%>").val();
var dlDO = $("#<%=ddlDO.ClientID%> option:selected").text();
//Week
var dlWeek = $("#<%=ddlWeek.ClientID%>").val();
//Dealer
var dlDealer = $("#<%=ddlDealer.ClientID%>").val();
DistributionDtl = new Object();
DistributionDtl.DOId = dlDOId;
DistributionDtl.DONo = dlDO;
DistributionDtl.DealerCode = dlDealer;
DistributionDtl.Week = dlWeek;
DistributionDtl.Item = dlItem;
DistributionDtl.Qty = dlQty;
DistributionDtl.Date = dlDt;
//alert(DistributionDtl);
arrobj.push(DistributionDtl);
JSONString = JSON.stringify(arrobj);
//alert(JSONString);
$("#list").jqGrid('setGridParam',
{ datatype: "local",
data: JSONString
}).trigger("reloadGrid");
});
jQuery("#list").jqGrid({ data: JSONString,
datatype: "local",
height: 150,
width: 600,
rowNum: 10,
rowList: [10, 20, 30],
colNames: ['DOID', 'Item', 'Qty', 'Date'],
colModel: [{ name: 'DOId', index: 'DOId', width: 60, sorttype: "int" },
{ name: 'Item', index: 'Item', width: 120 },
{ name: 'Qty', index: 'Qty', width: 80 },
{ name: 'Date', index: 'Date', width: 120}],
pager: "#pager",
viewrecords: true,
caption: "Contacts"
});
});

You should add data local to jqgrid with any of the following methods:
addJSONData - with data as json
addRowData - adding row by row and then trigger reload grid to recalculate pagination - data should be a javascript object
Documentation can be found here. Edit: According to the documentation you CAN set local data directly in the "data" param but it should be an array not a json string and you do not have the contents of JSONString in your question, so the problem might come from that.

Related

How to mapping variable data for pie chart (react.js)

I want make pie chart using state value in react with '#toast-ui/react-chart'.
I tried this and that after looking at the examples, but it's hard to me.
This is a example.
//chart data
var data = {
categories: ['June, 2015'],
series: [
{
name: 'Budget',
data: [5000]
},
{
name: 'Income',
data: [8000]
},
{
name: 'Expenses',
data: [4000]
},
{
name: 'Debt',
data: [6000]
}
]
};
var options = {
chart: {
width: 660,
height: 560,
title: 'Today's Channel & Value.'
}
tooltip: {
suffix: 'value'
}
},
};
var theme = {
series: {
colors: [
'#83b14e', '#458a3f', '#295ba0', '#2a4175', '#289399',
'#289399', '#617178', '#8a9a9a', '#516f7d', '#dddddd'
]
}
};
//render part
render()
{
return(
<div>
<PieChart
data={data}
options={options}
/>
</div>
}
and document is here.
https://github.com/nhn/toast-ui.react-chart#props
https://nhn.github.io/tui.chart/latest/tutorial-example07-01-pie-chart-basic
What's in the document is how to make a chart with a fixed number, but I want to change it using the state.
So, How can I mapping series data like this and how to add data length flexible?
I have list of object like ...
this.state.list =[{"channel_name":"A","channel_number":17,"VALUE":3,"num":1},
{"channel_name":"B","channel_number":23,"VALUE":1,"num":2},
{"channel_name":"C","channel_number":20,"VALUE":1,"num":3},
{"channel_name":"D","channel_number":1,"VALUE":1,"num":4}]
The length of the list is between 1 and 7 depending on the results of the query.
I want to do like this.
series:[
{
name: this.state.list[0].channel_name+this.state.list[0].channel_num
data: this.state.list[0].VALUE
},
{
name: this.state.list[1].channel_name+this.state.list[1].channel_num
data: this.state.list[1].VALUE
},
{
name: this.state.list[2].channel_name+this.state.list[2].channel_num
data: this.state.list[2].VALUE
},
{
name: this.state.list[3].channel_name+this.state.list[3].channel_num
data: this.state.list[3].VALUE
}
]
How can I implement it however I want?
Since this.state.list is a list of objects, so you can simply use map method to loop through each object https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map. Then create new object with custom value.
let new_series = [];
this.state.list.map((obj) => {
let info = {
name: obj.channel_name + obj.channel_number, //from your code
data: obj.VALUE //from your code
}
new_series.push(info)
});
Then assign new list to your chart.
//chart data
var data = {
categories: ['June, 2015'],
series: new_series
]
};

Mongodb - Create entry to a extisting collection field array

So I have a problem with my var array to add a new chapter, how would I go about this would I have to do this:
array.push({
chapter: [
{
id: 2,
title: 'adsf',
content: '',
authorNotes: 'asdf'
}
]
});
RiTest.ts
import * as mongoose from 'mongoose';
const Scheme = mongoose.Schema;
export const RiTestScheme = new Scheme({
novelName: String,
novelAuthor: String,
novelCoverArt: String,
novelTags: Array,
chapters: [
{
id: Number,
title: String,
content: String,
authorNotes: String
}
]
});
export class RiTestController {
public addChapter(callback: (data) => void) {
var chapterInfoModel = mongoose.model('ChaptersTest', RiTestScheme);
var array = [
{
chapter: [
{
id: 0,
title: 'prolog',
content: 'conetntt is empty',
authorNotes: 'nothing is said by author'
},
{
id: 1,
title: 'making a sword',
content: 'mine craft end chapter',
authorNotes: 'nothing'
}
]
}
];
let newChapterInfo = new chapterInfoModel(array);
newChapterInfo.save((err, book) => {
if (err) {
return callback(err);
} else if (!err) {
return callback(book);
}
});
}
}
This doesn't work, var array doesn't get saved into let newChapterInfo = new chapterInfoModel(array); what I am trying to do add another chapter to array.chapter but the array doesn't get recognized in the chapterInfoModel() how would I fix this array and add an item to the array to create a new entry into this existing collection
thank for taking your time to answer my question.
You are trying to insert array of document to your collections, That the reason its not inserting into your collection.
Document.prototype.save() will insert only one document to your collection depends on your definition. So to insert chapter here is the code below,
//array as Object
var array = {
chapter: [
{
id: 0,
title: 'prolog',
content: 'conetntt is empty',
authorNotes: 'nothing is said by author'
},
{
id: 1,
title: 'making a sword',
content: 'mine craft end chapter',
authorNotes: 'nothing'
}
]
};
//Push to your chapter array
array.chapter.push({
id: 2,
title: 'adsf',
content: '',
authorNotes: 'asdf'
});
let newChapterInfo = new chapterInfoModel(array);

Get only values from the array of array using angular js

I got an array from database as
[
{id:
{unitno: 'abc'},
amount: 100},
{id:
{unitno: 'xyz'},
amount: 150}
]
Now my required answer is that should be in the following format,
[["abc",100],
["xyz",150]]
But after some coding I got an array of Array as shown below in the console
[0:[0:"abc",1:100]
1:[0:"xyz",1:150]]
Before question down / marking duplicate please read my requirement, and if its there then mark it and please post that link as per my required solution so i can get my solution from there
So any help will be great help....
You can do like this:
data = [
{id:
{unitno: 'abc'},
amount: 100},
{id:
{unitno: 'xyz'},
amount: 150}
]
var array =[]
data.forEach(function(item){
var tmpArray = []
tmpArray.push(item.id.unitno,item.amount)
array.push(tmpArray)
})
Now you will get your required data in the array.
I don't know how you got this below code, but that's invalid Array
[0:[0:"abc",1:100] 1:[0:"xyz",1:150]]
For your desired output you can do it with JavaScript, no need angular. Just run a simple for loop.
var temp1 = [{
id: {
unitno: 'abc'
},
amount: 100
}, {
id: {
unitno: 'xyz'
},
amount: 150
}];
var eee = [];
temp1.forEach(function(el) {
eee.push([el.id.unitno, el.amount])
});
console.log('eee:', eee);
Hope this is what you needed.
var arr = [{
id : { unitno: 'abc' },
amount: 100
},{
id : { unitno: 'xyz' },
amount: 150
}];
var result = [];
for (var i = 0; i < arr.length; i++) {
var newArray = [];
newArray.push( arr[i]["id"]["unitno"] );
newArray.push( arr[i]["amount"] );
result.push( newArray );
}
console.log( result );

Add summary row in qx.ui.table.Table for column

How can i add a summary row to a qx.ui.table.Table to display a total for a column.
The only idea yet is to combine two tables, one with the data and one with the totals. Is there any more elegant way how i can handle this?
Edit
The table is used with the qx.ui.table.model.Simpleas table model.
Well, as long as you use qx.ui.table.model.Simple, you can calculate summary row and append it to the data array before passing it to the model. Or you can do it in a listener of the model's dataChanged. Also it's possible to subclass qx.ui.table.rowrenderer.Default to emphasize the row in some way.
Here goes example and here's playground snippet:
qx.Class.define("app.SummaryRowRenderer", {
extend : qx.ui.table.rowrenderer.Default,
members : {
// override
getRowClass : function(rowInfo)
{
var model = rowInfo['table'].getTableModel();
var isSummaryIndex = model.getColumnIndexById('_isSummary');
return rowInfo['rowData'][isSummaryIndex] ? 'summary' : '';
}
},
defer : function()
{
var entry = qx.bom.element.Style.compile({
'backgroundColor' : '#ccc',
'fontWeight' : 'bold'
});
var sheet = qx.bom.Stylesheet.createElement();
qx.bom.Stylesheet.addRule(sheet, '.summary .qooxdoo-table-cell', entry);
}
});
var model = new qx.ui.table.model.Simple();
model.setColumns(
[this.tr('Name'), this.tr('Value'), null],
['name', 'value', '_isSummary']
);
var table = new qx.ui.table.Table(model);
table.set({
'statusBarVisible' : false,
'columnVisibilityButtonVisible' : false,
'showCellFocusIndicator' : false,
'dataRowRenderer' : new app.SummaryRowRenderer()
});
table.getTableColumnModel().setColumnVisible(2, false);
this.getRoot().add(table, {'edge': 0});
var data = [
{'name': 'foo', 'value': 10},
{'name': 'bar', 'value': 100},
{'name': 'baz', 'value': 1000},
{'name': 'quz', 'value': 10000},
];
qx.event.Timer.once(function()
{
var dataWithSummary = qx.lang.Array.clone(data);
dataWithSummary.push(data.reduce(function(r, v)
{
r['value'] += v['value'];
return r;
}, {'name': 'Summary', 'value': 0, '_isSummary': true}));
model.setDataAsMapArray(data);
}, this, 1000);

How do I get my Filters from Filtersfeature

I am using FiltersFeature:
this.features = {
ftype: 'filters',
encode: false,
local: true
};
I would like to access my current filters on my table. Ie. not the filter configuration object, but what the changes user has done to the table (I want to save this in the database).
There is a filters object on grid, but that just gives me the filter configuration from all the columns.
handler: function (btn) {
var grid = btn.up('grid');
grid.filters
}
I need the actual values. I'm looking for something like this:
var v = {
filter: {
column: 'name',
value: 'bob'
},
filter: {
column: 'date',
value1: '11.11.11',
value2: '12.12.12'
}
}
Anyone know where i can get this info?
The answer I found out was to use this method :)
myTableGrid.filters.getFilterData()
I get something like this :
v = [{
"field": "myColumn1",
"data": {
"type": "string",
"value": "anna"}
}, {
"field": "myColumn2_fixedvalue",
"data": {
"type": "list",
"value": [60]}
}]
Filter does not contain any values.
You should parse actual values from the grid.
var columnTitle = [];
var fieldName = [];
var data = [];
var visibleColumns = grid.query('gridcolumn:not([hidden])');
visibleColumns.forEach(function(c) {
columnTitle.push(c.text);
fieldName.push(c.dataIndex);
});
for (rowIndex = 0; rowIndex < grid.store.getCount(); rowIndex++) {
var row = grid.getView().getRow(rowIndex);
var fieldValues = Ext.fly(row).query('div.x-grid-cell-inner');
var map = {}
for (colIndex = 0; colIndex < fieldName.length; colIndex++) {
map[fieldName[colIndex]] = fieldValues[colIndex].textContent;
}
data.push(map);
}
As a result, you will get an array of objects, something like
[{"user.login":"iivanov","email":"ivanov#mail.com"},{"user.login":"ppetrov","email":"petrov#mail.com"},{"user.login":"plosev","email":"elk#gmail.com"}]

Resources