I dont understand how to create two date columns and create range between them?
For example I have Grid where is some column (deadline date), and i have 2 datefields, where I can write: From what day and Till what day .
How then I can filter data between those days that I choosed?
**SOME CODE:**
// create the Grid
var grid = new Ext.grid.GridPanel({
store : store,
id : 'grid',
columns : [
new Ext.grid.RowNumberer({width: 20, header: '#'}),
{id:'text',header: "Text", width: 150, sortable: true, dataIndex: 'text'},
{id:'is_online',header: "Is Online?", width: 70, sortable: true, dataIndex: 'is_online'},
{id:'deadline',header: "Deadline", width: 130, sortable: true, dataIndex: 'deadline', xtype: "datecolumn", format: "Y-m-d"}
],
stripeRows : true,
height : 550,
title : 'Questions',
});
var gridSearch = new Ext.Panel({
stripeRows : true,
frame : true,
style : 'padding-bottom: 5px',
height : 250,
title : 'Search filter',
items : [{
xtype : 'checkbox',
id : 'is_for_online',
boxLabel : 'Показать только ОНЛАЙН',
inputValue : '1'
},{
xtype : 'datefield',
id : 'date_s',
allowBlank : true,
emptyText : 'Выберите дату С',
name : 'deadline',
width : 140,
editable : false,
format : 'Y-m-d'
},{
xtype : 'datefield',
id : 'date_s',
allowBlank : true,
emptyText : 'Выберите дату С',
name : 'deadline',
width : 140,
editable : false,
format : 'Y-m-d'
},{
xtype : 'button',
text : 'Go!',
handler : function () {
//var searchValueDate1 = Ext.getCmp("date_s").getValue();
//var searchValueDate2 = Ext.getCmp("date_po").getValue();
//var date_s = searchValueDate1.format('Y-m-d');
//var date_po = searchValueDate2.format('Y-m-d');
//store.filter("deadline", date_s)//, date_po);
alert(daterange);
}
},
]
});
You can also use multiple filters by same property, but add different id to each filter.
This makes much clear code.
store.filter([
{
id: "deadlineStart",
property: "deadline",
operator: ">",
value: new Date(2017, 0, 1)
},
{
id: "deadlineEnd",
property: "deadline",
operator: "<",
value: new Date()
}
]);
So what you want to do is have a user select a start and end date and in the grid filter out and show only the records with deadline dates between that range? Say you have field where the user enters the date range and click a button to filter on the filter button click. Get the date range from the two fields (I assume you'll have logic to make sure the user has enter a valid date range ie the start date is before the end date etc.)
Then try the following:
On the button click handler below
var grid = Ext.getCmp('grid');//Get the grid
var store = grid.store; //get the store from the grid to filter
//This method loops through each record return true to keep the record false to filter it //out
store.filterBy(function(rec, id){
var startDate = Ext.getCmp('dateFieldStart');
var endDate = Ext.getCmp('dateFieldEnd');
var deadLineDate = rec.data.deadline;
//Then here I'm not going to write all the code you need to see if the date of the record //is between the start and end range if so return true to keep the row in the grid and //return false to filter it out
if(in the range){
return true;
}else {
return false.
}
});
Here my example:
Ext.create('Ext.grid.Panel', {
id: 'destinationsGrid',
features: [{
ftype: 'filters',
encode: false,
local: false, // defaults to false (remote filtering)
filters: [
{ type:'list', dataIndex: 'status',/* phpMode: true,*/ options: [[1,'Прошел'], [0, 'Не прошел'] ]}
]
}],
columns: [
{ text: 'ФИО', flex: 1, dataIndex: 'fio', filter: {type: 'string'} },
{ text: 'Дата начало', dataIndex: 'start_date', filter: { type: 'date' }, xtype: "datecolumn", format: "d.m.Y" },
...
tbar: [
{
xtype: 'textfield',
emptyText: 'Найти участника',
id: 'findUserInGrid',
width: 350,
listeners: {
change: function(data, record){
var value = record;
var grid = Ext.getCmp('destinationsGrid'),
filter = grid.filters.getFilter('fio');
if (!filter) {
filter = grid.filters.addFilter({
active: true,
type: 'string',
dataIndex: 'fio'
});
filter.menu.show();
filter.setValue(value);
filter.menu.hide();
} else {
filter.setValue(value);
filter.setActive(true);
}
}
}
}
and:
listeners: {
change: function(data, record){
var value = record;
var grid = Ext.getCmp('destinationsGrid'),
filter = grid.filters.getFilter('fio');
if (!filter) {
filter = grid.filters.addFilter({
active: true,
type: 'string',
dataIndex: 'fio'
});
filter.menu.show();
filter.setValue(value);
filter.menu.hide();
} else {
filter.setValue(value);
filter.setActive(true);
}
}
}
Related
enter image description hereI have 4 columns, namely Quantity, wastage, cost, Final Cost in a grid. at the last row of my grid, I have to show consolidated Final Cost, and nothing else.
My problem is,in last row Quantity, wastage, and Cost column, 0 is shown, whereas in store data for these column aren't there for last row.
I just want to show empty value on these columns.
data: [{"Name":"Part-0000112-01","Wastage":"4.63","Unit_Cost":"7.00","Quantity":"7.2200","Type":"Fabric","Net_Consumption":"11.8500","totalCost":"82.95"},{"Name":"Part-0000114-01","Wastage":"0.0","Unit_Cost":"1.00","Quantity":"10.0000","Type":"Fabric","Net_Consumption":"10.0000","totalCost":"10.00"},{"Name":"Part-0000116-01","Wastage":"2.0","Unit_Cost":"1.00","Quantity":"10.0000","Type":"Trim","Net_Consumption":"12.0000","totalCost":"12.00",},{"Name":"Part-0000118-01","Wastage":"0.0","Unit_Cost":"0.00","Quantity":"10.0000","Type":"Trim","Net_Consumption":"10.0000","totalCost":"0.00"},{"totalCost":"104.95","Name":"Total Material Costs (InDollar)"}]
Code:
Ext.create('Ext.grid.Panel', {
store: BOMStore,
columns: [{
text: 'Name',
dataIndex: 'name'
}, {
text: 'Quantity',
dataIndex: 'Quantity',
editor: {
xtype : 'numberfield',
allowBlank : false,
listeners : {
change : function(field, newValue,o ,e) {
var quantity = field.value;
var selectedModel = this.up('grid').getSelectionModel().getSelection()[0];
var wastage = selectedModel.get('Wastage');
var unitCost = selectedModel.get('Unit_Cost');
var updateTotalCost = getTotalCost(quantity,wastage,unitCost);
selectedModel.set('totalCost', updateTotalCost);
updateRowCosting(selectedModel);
}
}
}
}, {
text: 'Wastage',
dataIndex: 'Wastage',
editor: {
xtype : 'numberfield',
allowBlank : false,
}
},{
text: 'Cost',
dataIndex: 'Unit_Cost',
editor: {
xtype : 'numberfield',
allowBlank : false,
}
},{
text: 'Total Cost',
dataIndex: 'totalCost',
editor: {
xtype : 'numberfield',
allowBlank : false,
}
}]
});
You can use renderer which can be used as a converter, so you can check if the row is last one and return empty string.
FIDDLE
Ext.create('Ext.grid.Panel', {
store: Ext.data.StoreManager.lookup('simpsonsStore'),
columns: [{
text: 'Name',
dataIndex: 'name'
}, {
text: 'Email',
dataIndex: 'email',
flex: 1
}, {
text: 'Phone',
dataIndex: 'numm',
renderer: function (value, metaData, record, rowIndex, collIndex, store) {
if (store.indexOf(record) === (store.totalCount - 1)) {
return '';
}
return value;
}
}]
});
The issue got resolved.
Below is my model.
fields: [ 'Type', 'matid', 'ebomid' , 'srmid' ,'Name', 'Component_Location','Description',
'Article','Supplier_Item_Label','Supplier_Item_Description','UOM',
{ name: 'Quantity', type: 'float' },{ name: 'Wastage', type: 'float' },'Wastage_Percentage','Net_Consumption','Material_Currency','Target_Cost',
'markupInViewMode',{ name: 'Markup', type: 'float' },'markup_Percentage','Final_Material_Cost','Sourcing_Classification','Brand_Cost','Vendor_Cost','Total_Cost']
});
So, if I give type float/number in Model, and dont pass the data for corresponding columns, then defaults the value to 0.
We got to set the field type in column. xtype : 'numberfield',
I have to append a value to the data fetched from the store before rendering it to the grid in ExtJs.
Please guide me on achieving the above mentioned functionality.
Currently the grid is populated in the following manner:
Ext.define("MyApp.view.ShowDetails",{
extend: 'Ext.grid.Panel',
requires:['MyApp.store.MyStore'],
store:'MyStore',
stateId: 'stateGrid',
selType : 'checkboxmodel',
selModel : {
mode : 'MULTI'
},
plugins : [Ext.create('Ext.grid.plugin.RowEditing', {
clicksToEdit : 2
})],
defaultType: 'textfield',
columns: [
{
header: 'Userid',
width: 150,
dataIndex: 'uid',
editor :
{
allowBlank : true
}
},
...
Yes this is possible,using the convert property in field declaration in MODEL
An Example:
{
name: 'uid',
type: 'string',
convert: function (value, record) {
if (!value)
return value+'D';
else
return value;
}
},
Using ExtJS 4.2.2
I have a grid, and when I right click the grid and select Modify from my context menu, a Window with a form is created, and on render, I get the grid selected row record and use the form loadRecord to load the record.
Firebug shows the record was loaded into the form fields, but in the rendered form the fields are enpty.
Any ideas?
Here is some code that illustrates the issue.
If you put a breakpoint at the line with var test = 'test'; you will see the data is loaded into the form's textfields, but then continue past the break point and see the textfields do not reflect the data.
Ext.onReady(function() {
Ext.define('com.myCompany.MyGridModel', {
extend : 'Ext.data.Model',
fields : [{
name : 'name',
type : 'string'
}, {
name : 'address',
type : 'string'
}, {
name : 'type',
type : 'string'
}]
});
var store = Ext.create('Ext.data.Store', {
model: 'com.myCompany.MyGridModel',
proxy: {
type: 'ajax',
url: 'centers.json',
reader: {
type: 'json',
root: 'centers'
}
}
});
store.load();
var grid = Ext.create('Ext.grid.Panel', {
layout: 'fit',
store: store,
columns: [{
text: 'Name',
dataIndex: 'name',
name: 'name'
}, {
text: 'IP Address',
dataIndex: 'address',
name: 'address'
}, {
text: 'Type',
dataIndex: 'type',
name: 'type'
}],
renderTo: Ext.getBody(),
listeners: {
itemcontextmenu : function(view, record, item, index, event){
var selectedItem = record;
event.preventDefault();
new Ext.menu.Menu({
items: [{
text : 'Modify',
handler : function(widget, event) {
Ext.create('Ext.window.Window', {
height : 380,
width : 540,
resizable : false,
closable: true,
modal: true,
layout :{
type : 'fit'
},
items : [{
xtype : 'form',
frame : true,
height : 250,
itemId : 'centerContentForm',
width : 400,
bodyPadding : 10,
items : [{
xtype : 'textfield',
itemId : 'txtName',
height : 30,
width : 401,
fieldLabel : 'Name',
name: 'name',
allowBlank : false
},{
xtype : 'textfield',
itemId : 'txtIPAddress',
height : 30,
width : 401,
fieldLabel : 'Address',
name: 'address',
allowBlank : false,
},{
xtype : 'textfield',
itemId : 'txtType',
height : 30,
width : 401,
fieldLabel : 'Type',
name: 'type',
allowBlank : false
}]
}],
listeners: {
render: function(win) {
win.down('form').loadRecord(selectedItem);
var test = 'test';
}
}
}).show();
} // end of right-click handler
}]
}).showAt(event.getXY());
}
}
});
grid.getView().refresh();
});
Instead of render event handler you should use afterrender event handler.
So your window listeners config should be:
listeners: {
afterrender: function(win) {
win.down('form').loadRecord(selectedItem);
}
}
I defined a GridPanel with pre-configured ColumnModel and Store, and put this GridPanel in a Ext.Window; It works fine when this window shows, however, if I close it and show it again, the ColumnModel of GridPanel becomes null so that this GridPanel cannot correctly rendered.
UPDATED (all code)
var stSummary = new Ext.data.JsonStore({ //define the store for Summary_Grid
fields : [
{
name: 'recID'
}, {
name : 'name',
}],
data: []
});
var colModelSummary = { //define the ColumnModel for Summary_Grid
columns:
[
{
header : "ID",
width : 50,
sortable : true,
menuDisabled: true,
dataIndex : 'recID'
},
{
header : "Name",
width : 100,
sortable : true,
menuDisabled: true,
dataIndex : 'name'
}
]
};
var reportConfig = {
id : 'Report_Window',
width : 250,
floating : true,
style : {
opacity : 0.7,
},
title : "Report",
layout: 'fit',
items : [{
xtype: 'tabpanel',
id: 'Report_Tab',
height: 200,
activeTab: 1,
items:
[
{
xtype : 'grid',
store : stSummary,
colModel : new Ext.grid.ColumnModel(colModelSummary),
stripeRows : true,
id : "Summary_Grid",
title : "Summary at",
sm : new Ext.grid.RowSelectionModel({
singleSelect : true
}),
listeners: {
'beforerender': function() {
console.log(this.getColumnModel().getColumnCount());
}
}
},
{
xtype : 'form',
id : 'Report_Form',
title: 'Item Report',
frame : true,
labelAlign : 'left',
bodyStyle : 'padding:2px',
autoScroll: true,
layout : 'column',
items : []
}
]
}],
resizable : {
dynamic : true
}
};
var reportWindow = new Ext.Window(reportConfig);
reportWindow.show();
document.onclick = myClickHandler;
function myClickHandler() {
if(!Ext.getCmp('Report_Window')) {
var reportWindow = new Ext.Window(reportConfig);
}
Ext.getCmp('Report_Window').show();
}
});
and the error:
Uncaught TypeError: Cannot read property 'length' of undefined
Ext.grid.ColumnModel.Ext.extend.getColumnCount ext-all.js:11
I actually just copy pasted your code into my application. I added reportWindow.show() in the end - and it works! Not sure what could be wrong, can you show all code?
Please note that it might be a close/hide problem, do you recreate your window each time?
EDIT:
Try to set closeAction: 'hide' to your window configuration.
Check this for details:
http://docs.sencha.com/ext-js/3-4/#!/api/Ext.Window-cfg-closeAction
EDIT #2:
I tested your code again, and it works again! I only corrected several things like extra commas - my resharper suggested it. (It might cause problems in IE) Then I putted it into Ext.onReady - it works! Ext.version == '3.2.1'
Check the whole code:
Ext.onReady(function() {
var stSummary = new Ext.data.JsonStore({
//define the store for Summary_Grid
fields: [
{
name: 'recID'
}, {
name: 'name'
}],
data: []
});
var colModelSummary = {
//define the ColumnModel for Summary_Grid
columns:
[
{
header: "ID",
width: 50,
sortable: true,
menuDisabled: true,
dataIndex: 'recID'
},
{
header: "Name",
width: 100,
sortable: true,
menuDisabled: true,
dataIndex: 'name'
}
]
};
var reportConfig = {
id: 'Report_Window',
width: 250,
floating: true,
style: {
opacity: 0.7
},
title: "Report",
layout: 'fit',
items: [{
xtype: 'tabpanel',
id: 'Report_Tab',
height: 200,
activeTab: 1,
items:
[
{
xtype: 'grid',
store: stSummary,
colModel: new Ext.grid.ColumnModel(colModelSummary),
stripeRows: true,
id: "Summary_Grid",
title: "Summary at",
sm: new Ext.grid.RowSelectionModel({
singleSelect: true
}),
listeners: {
'beforerender': function() {
console.log(this.getColumnModel().getColumnCount());
}
}
},
{
xtype: 'form',
id: 'Report_Form',
title: 'Item Report',
frame: true,
labelAlign: 'left',
bodyStyle: 'padding:2px',
autoScroll: true,
layout: 'column',
items: []
}
]
}],
resizable: {
dynamic: true
}
};
var reportWindow = new Ext.Window(reportConfig);
reportWindow.show();
document.onclick = myClickHandler;
function myClickHandler() {
if (!Ext.getCmp('Report_Window')) {
reportWindow = new Ext.Window(reportConfig);
}
Ext.getCmp('Report_Window').show();
}
});
I am using this article of architecture http://blog.extjs.eu/know-how/writing-a-big-application-in-ext/
here is my Application.ResellerIroGrid.js
the pagination buttons are coming but no. of pages and pageno. is not coming .
Application.ResellerIroGrid = Ext.extend(Ext.grid.GridPanel, {
border:false
,cityname : ''
,columndataindex : ''
,fromdate:''
,todate : ''
,initComponent:function() {
var config = {
store:new Ext.data.JsonStore({
// store configs
autoDestroy: true,
autoLoad :false
,method: 'GET'
,baseParams: {
_command:'getresellersiro'
,city:this.cityname
,columndataindex : this.columndataindex
,fromdate : this.fromdate
,todate : this.todate
}
,url: 'api/index.php'
// reader configs
,root: 'reseller'
,totalProperty: 'totalcount'
,idProperty: 'mobile',
fields: [
{name: 'caller'},
{name: 'designa'},
{name: 'mobile'},
{name: 'app_date'},
{name: 'transferto'},
{name: 'data_city'},
{name: 'AllocatedTo'},
{name: 'Parentid'},
{name: 'gotthru'}
]
})
,columns: [
{
id :'caller',
header : 'Caller',
width : 120,
sortable : true,
dataIndex: 'caller'
},
{
id :'designa',
header : ' Designation',
width : 100,
sortable : true,
dataIndex: 'designa'
},
{
id :'mobile',
header : 'Mobile',
height : 50,
width : 100,
sortable : true,
dataIndex: 'mobile'
},
{
id :'app_date',
header : ' Appointment Date',
width : 100,
sortable : true,
dataIndex : 'app_date'
},
{
id :'transferto',
header : ' Transfered To',
width : 100,
sortable : true,
dataIndex: 'transferto'
},
{
id :'data_city',
header : ' Data City',
width : 100,
sortable : true,
dataIndex: 'data_city'
},
{
id :'AllocatedTo',
header : ' Allocated To',
width : 100,
sortable : true,
dataIndex: 'AllocatedTo'
},
{
id :'Parentid',
header : ' Parent Id',
width : 100,
sortable : true,
dataIndex: 'Parentid'
},
{
id :'gotthru',
header : ' Appointment Type',
width : 100,
sortable : true,
dataIndex: 'gotthru'
}
]
,plugins :[]
,viewConfig :{forceFit:true}
,tbar :[]
,bbar: new Ext.PagingToolbar({
pageSize: 5,
store: this.store,
displayInfo: true,
displayMsg: 'Displaying topics {0} - {1} of {2}',
emptyMsg: "No topics to display"
})
,height : 250
,width : 860
,title : 'Reseller Iro Grid'
}; // eo config object
// apply config
Ext.apply(this, Ext.apply(this.initialConfig, config));
Application.ResellerIroGrid.superclass.initComponent.apply(this, arguments);
} // eo function initComponent
,onRender:function() {
this.store.load();
Application.ResellerIroGrid.superclass.onRender.apply(this, arguments);
} // eo function onRender
});
Ext.reg('ResellerIroGrid', Application.ResellerIroGrid);
You need to have a totalProperty attribute in your Store or JsonReader config and this property must be sent by ther server JSON.
Eg :
,totalProperty: 'totalCount'
,root: 'reseller',
,idProperty: 'caller'
Also, dont hardcode params in the store url property. You should use the baseParams config option for this :
method:'GET'
,baseParams: {
_command:'getresellersiro'
,city:this.cityname
[...]
}
,url:'api/index.php'
And of course you should have a PagingToolbar declared for your grid in the initComponent :
var pagesize = 5;
var store = new Ext.data.JsonStore({
[...]
,params:{start:0, limit:pagesize}
});
var paging_toolbar = new Ext.PagingToolbar({
pageSize: pagesize,
displayInfo: true,
emptyMsg: 'No data',
store: store
});
var grid = new Ext.grid.GridPanel({
store:store,
[...]
bbar:paging_toolbar
});