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

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);

Related

get single object which is having highest date from list of objects in angularJs

New to angularJs and want to get max dated object from list of object.
I have list of customers with property CreatedOn (date)
I want to get single customer and set a property
customer.CurrentCustomer = true; //// when customer having max date
customers.sort(function(a,b) {
return new Date(a.CreatedOn).getTime() - new Date(b.CreatedOn).getTime()
});
This will sort your array in ascending order by the field CreatedOn.
Then you can pick the last item by:
customers[customers.length - 1]
and hence set the CurrentCustomer:
customers[customers.length - 1].CurrentCustomer = true;
Use angularjs orderByFilter
function MyCtrl($scope, orderByFilter) {
$scope.customer = orderByFilter($scope. customers, 'CreatedOn')[0];
$scope.customer.CurrentCustomer=true
}
You can use libraries like Underscore, Ramda or Lodash. An example using Lodash can be found as given below and in the Link
var users = [
{ 'user': 'fred', 'age': 48 },
{ 'user': 'barney', 'age': 36 },
{ 'user': 'fred', 'age': 40 },
{ 'user': 'barney', 'age': 34 }
];
_.sortBy(users, ['user', 'age']);
An example using Ramda:
var diff = function(a, b) { return a.id > b.id; };
R.sort(diff, [
{ id: 4 },
{ id: 2 },
{ id: 7 },
{id: 5}
]);

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"}]

JQGrid data from Local Object array

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.

jQplot treat each item as a new one

I am using jQplot for a bar graph but I've run into problem.
Here is some sample data:
var s2 = [["28",425, null], ["23",424], ["24",417], ["25",390],["26",393], ["27",392], ["28",369]];
The problem i have is there are two values the same e.g. 28 and jQplot treats this as the same item is there a way to make it treat this as a separate value?
Break your data and labels into two separate arrays (data and ticks), then use the CategoryAxisRenderer:
$(document).ready(function(){
ticks = ['One', 'Two', 'Three', 'One', 'Two', 'One'];
data = [12,14,6,21,17, 21];
var opts = {
seriesDefaults: {
renderer: jQuery.jqplot.BarRenderer
},
axes: {
xaxis: {
renderer: $.jqplot.CategoryAxisRenderer,
ticks: ticks
}
}
};
plot1 = jQuery.jqplot ('chart1', [data], opts);
});
Fiddle here.

How to add records in json-store

var store = new Ext.data.JsonStore({
id:'jfields',
totalProperty:'totalcount',
root:'rows',
url: 'data.php',
fields:[{ name:'jfields' },
{ name:'firstyear' , mapping :'firstyear' , type:'float' },
{ name:'secondyear', mapping :'secondyear', type:'float' },
{ name:'thirdyear' , mapping :'thirdyear' , type:'float' },
{ name:'fourthyear', mapping :'fourthyear', type:'float' },
{ name:'fifthyear' , mapping :'fifthyear' , type:'float' } ]
}
});
What I want is to add data at the end for this store , but I am totally confused , what I did is I add the following code to it but not working.
listeners: {
load : function(){
BG_store.add([{"jfields":"Monthly","firstyear":22.99,"secondyear":21.88,"thirdyear":21.88,"fourthyear":22.99,"fifthyear":21.88}]);
}
}
But I do not think my concept are cleared ,Please any body show some way how to do it .
You need to define a record type, create it and at it, e.g:
TaskLocation = Ext.data.Record.create([
{name: "id", type: "string"},
{name: "type", type: "string"},
{name: "type_data", type: "string"},
{name: "display_value", type: "string"}
]);
Then:
var record = new TaskLocation({
id: Ext.id(),
type: "city",
type_data: "",
display_value: "Brighton"
});
Then:
my_store.add(record);
my_store.commitChanges();
Remember by the time the data is in the store it's not in the same format as you sent it down but in Record objects instead.
See the recordType property in the JsonStore. It's a function that can be used as a record constructor for the store in question. Use it like this:
var newRecord = new myStore.recordType(recordData, recordId);
myStore.add(newRecord);
I have also figured out a simple solution to this:
listeners: {
load: function( xstore , record , option ) {
var u = new xstore.recordType({ jfields : 'monthly' });
xstore.insert(record.length, u);
}
}
Here what I have to add is this listeners as when the data loads it will create the record type and u can add fields as data as many as u want

Resources