I want to add total row in grid footer. I have total row that record is available in store. In grid the user selects descending order, total row appears as the first row. Can anybody tell me how to avoid this?
I will explain my full problem:
eg I have grid view like Target Target1 Target2 are getting from webservice
Month Target Target1 Target2 Target(2-1) Target%
jan 500 1000 1001 1 0.99
feb 600 2000 2001 1 0.99
**total 1100 3000 3002 2 2*3002/100** need to calculate total% like this
I am calculating the value Target(2-1) Target% total value in store and bind the store in grid. So only the total column also changes. In grid the user selects descending order, total row also changes. Can anybody tell me how to avoid this?
Thanks
You should use the grid summary feature, instead of a regular row. Here is a fiddle that demonstrates the usage with your example, and with custom summaryType function that implements the calculation for your Target% total.
This is a better method than to do the summary calculation as a record in the store, you will not get into trouble with sorting and filtering.
Have a look here for documantation and live example. Basically, you need to add the feature to the grid like:
Ext.create('Ext.grid.Panel', {
...
features: [{
ftype: 'summary'
}],
...
And add a summaryType config to the columns you need, like:
columns: [{
dataIndex: 'name',
text: 'Name',
summaryType: 'sum',
...
And this is how the custom summaryType looks like:
dataIndex: 'targetPercent',
text: 'Target%',
summaryType: function(records){
var totals = records.reduce(function(sums, record){
return [sums[0] + record.data.target2,
sums[1] + record.data.targetDiff];
}, [0,0]);
return (totals[0] * totals[1]) / 100;
}
Related
i trying to find some way to display/insert/update the information on the form where the information is dynamic. the extjs i currently using is Ext JS 7.1.x Classic
the schema are as below
name of item
cost price of the item
product code of the item
location ([latitude and longitude];rack number;shelves number)
remarks
For example the forms will have a list of location in the form for that item which i able to to add, delete and update each row of location?
data are as show below
PowerBank,10,MPB001,["000.1,111";2;2,"000.2,222";2;2,"000.1,111";1;2],My Power Bank
Earphone,4,MEP001,["000.1,111";2;3],My Earphone
i thinking of something like ListView or Datagrid?
For initial data, update data and insert you can use
form.setValues({
name: 'PowerBank',
cost: 10,
code: 'MPB001',
locationLatitude: '000.1',
locationLongitude: '111'
rack: 2,
shelves: 2,
remarks: 'My Power Bank'
});
Other than that you could use data-binding
data-binding
Let's say you have a grid and bind the selection:
xtype: 'grid',
bind: {selection: '{gridSelection}'}
And you have the selected dataset in your viewModel
data: {
gridSelection: null
}
Then you can add the data to the form like this:
items: {
xtype: 'textfield',
name: 'remarks',
bind: {value: '{gridSelection.remarks}'}
}
problem
you might run into a problem if you are trying to listen on the dirty states with data-binding. But you can solve this by making all fields not dirty after the data-binding triggers.
In the kitchen sink classic pivot grid configuration plugin example there are row numbers in the first column of the grid.
Does anyone know how to do this?
Here's the link to the example
https://examples.sencha.com/extjs/7.1.0/examples/kitchensink/?classic#configurable-pivot-grid
I tried setting rowNumbers to true but it didn't work
Thanks
rownumberer is column type. you must use it in columns
columns: [
{xtype: 'rownumberer'},
{text: "Company", flex: 1, sortable: true, dataIndex: 'company'},
]
Edited:
sorry for wrong answer. it was for ordinary grid. to show rowNumbeber on pivot grid set
selModel: {
type: 'spreadsheet'
},
I'm working with angular ui-grid version 3.0 and can not find the way to get the index of the row, to add a numeration column to the grid.
I would like to help me.
There isn't a way to get the index of the row easily, so it depends what you're trying to do. What do you expect the numbering to do when someone sorts the data - do you want the numbers to stay as they were in the original data, or do you want them to change and align to the new sort order?
In the FAQ http://ui-grid.info/docs/#/tutorial/499_FAQ we find:
The question here is what you're really trying to achieve. Do you want the actual row index, or that you want to display a sequential id in all your rows?
If the latter, then you can do it by just adding a counter column to your data:
$scope.myData.forEach( function( row, index){
row.sequence = index;
});
If you want to show the index of the row within the grid internals, then it depends on which internal you want. You can get the index of the row within grid.rows, which would show the row as it stands in the original rows list (not filtered nor sorted), or the index of the row within grid.renderContainers.body.visibleRowCache (filtered and sorted), or the render index of the row within the currently displayed rows (given virtualisation, this is generally a particularly useless number).
If you're OK that whenever someone sorts or filters then the numbers will change, then you could do it with a cellTemplate, which would be something like:
cellTemplate: '<div class="ui-grid-cell-contents">{{grid.renderContainers.body.visibleRowCache.indexOf(row)}}</div>'
cellTemplate: '
{{rowRenderIndex + 1}}'
the problem of first solution is that it does not work properly whith pagination. the celltemplate of index column must be something like this to have the right index on each page and not to begin from 1 on each page :
{ field: 'index', displayName: 'Index', width: '50', cellTemplate: '<div class="ui-grid-cell-contents">{{grid.renderContainers.body.visibleRowCache.indexOf(row)+(grid.options.paginationPageSize*(grid.options.paginationCurrentPage-1))+1}}</div>' }
this solution would work even for client-side pagination or for server-side pagination
by using this way to solve this problem...
$http.get('./api/ioni_users')
.success(function(data) {
$scope.gridOptions.data = data;
angular.forEach(data, function(data, index) {
data["index"] = index+1;
//data.push({"index":index+1})
})
});
The following worked for me as I needed to see the index of the row as it related to the entire dataset not just what was visible to the user. It can be cleaned up but this is the raw code that I was able to get to work using the formula
((0/100)+((2*100)-100))+1 where
0 = rowIndex (Zero Based)
100 = pagination page size
2 = current page
+1 = because the array is zero based
cellTemplate: '<div class="ui-grid-cell-contents">{{(((grid.renderContainers.body.visibleRowCache.indexOf(row) / grid.options.paginationPageSize)*100)+((grid.options.paginationPageSize * grid.options.paginationCurrentPage) - grid.options.paginationPageSize)) + 1}} </div>'
Hope this helps.
Use rowRenderIndex in your cell template, it is the native variable available on each row
E.g
columnDefs: [
{
enableFiltering: false,
enableSorting: false,
field: "sn",
displayName: "Sn#",
cellTemplate:
"<div class=\"ui-grid-cell-contents\" >{{rowRenderIndex}} s</div>"
}
]
Can someone help me to figure out a way to arrange the columns irrelevant of it columns array positioning? For example, in below grid columns array i just want to display Phone as 1st column and Name as 2nd column. How can i achieve that programmatically?
Columns Array:-
columns: [{
text: 'Name',
dataIndex: 'name'
}, {
text: 'Email',
dataIndex: 'email'
}, {
text: 'Phone',
dataIndex: 'phone'
}]
While debugging the grid column config with Chrome developer tools, i figured out a parameter "fullColumnIndex" which value getting increased for every column. But specifying that explicitly doesn't make any difference :(
Thanks!
You can do it by using reconfigure method. Docs — http://docs.sencha.com/extjs/5.1/5.1.0-apidocs/#!/api/Ext.panel.Table-method-reconfigure
Here is the description of this method:
reconfigure( [store], [columns] )
Reconfigures the grid / tree with a new store/columns. Either the store or the > columns can be omitted if you don't wish to change them.
The enableLocking config should be set to true before the reconfigure method is > executed if locked columns are intended to be used.
Parameters
store : Ext.data.Store (optional)
The new store. You can pass null if no new store.
columns : Object[] (optional)
An array of column configs
I have a grid Panel with 4 columns, one of these is numeric (number up to 4 digit), and I would like to sort the row by this colum. My problem is Ext JS sorts the rows as if the column was textual, so 5 is sorted after 3000.
I tried to use a numberColumn instead of a normal column (specifying the x-type in the columns of the GridPanel), but it doesn't change the sorting.
Thus I tried to format the numbers so 5 would appear like 0005, and 0005 would be before 3000. But the format options of the numberColumn do not appear to let me specify a minimal number of digit (in Java, using NumberFormat, 0000 would work, but here it doesn't).
So I put a renderer to force my number to appear with 4 digits, it works, but it seems that the sort method use the values before beeing rendered, wich is quite logical.
I'm stuck after trying all my ideas, does anyone have a clue?
If you're using a remote store sort, then the sorting is done remotely (the database, like mysql). So what is the type of column on the database for that field? If it's a char or varchar, then that's the issue.
I've had a similar issue, the column type doesn't fix this. To have a proper ordering the type in model should be numeric.
1) Set your field type as integer in model definition.
Ext.define('myModel', {
extend: 'Ext.data.Model',
fields: [{ name: 'myField', type: 'int' }]
});
2) Create a Store using that model.
var myStore = Ext.create('Ext.data.Store',{
model: 'myModel'
});
3) Define a GridPanel using the store and link your field as dataIndex into columns definition.
Ext.create('Ext.grid.Panel',{
store: myStore,
columns: [{
header: 'Numbers', dataIndex: 'myField'
}]
});
I encountered a similar problem where by exj grids sort by each digit in your number, so for example a list might be reordered to 1, 2, 22, 3, 4, 41, 5... for what its worth, i found in extjs4, that defining the type as int in the model did the trick, I havent specified the local or remote sort but it seems to be working...
Ext.define('ExtMVC.model.Contato', {
extend: 'Ext.data.Model',
fields: [{'id', type: 'int'}, 'name', 'phone', 'email']
});
This is my code that connects to a MySQL. I followed this -> {'id', type: 'int'}, and it work out fine... Thank you all! I'm using Ext js 4.2.x