Best way to block CTRL-V against a grid - extjs

Using the following fiddler https://fiddle.sencha.com/#fiddle/1frn
You can select cell, do CTRL-C, then select different cell, and do CTRL-V and you see the values have been copied.
How do I block CTRL-V?
Is overriding clipboard.validateAction the best way?
privates : {
validateAction : function(event) {
var view = this.getCmp().getView();
If(view.actionableMode){
return false;
}
}
}
Its not clear to me why a common function like validateAction would be private...

You can use this override/sample code to control the ability to paste depending on the current state of the grid:
Ext.define('Fiddle.grid.plugin.Clipboard',{
override: 'Ext.grid.plugin.Clipboard',
beforepaste: Ext.emptyFn,
mixins: [
'Ext.mixin.Observable'
],
constructor: function(config) {
var me = this;
me.callParent([config]);
me.mixins.observable.constructor.call(me);
},
privates : {
onPaste: function (keyCode, event) {
var me = this,
sharedData = me.shared.data,
source = me.getSource(),
i, n, s;
if (me.validateAction(event) === false) {
return;
}
if (me.fireEvent('beforepaste',keyCode,event,me.cmp) !== false) {
if (source) {
for (i = 0, n = source.length; i < n; ++i) {
s = source[i];
if (s === 'system') {
// get the format used by the system clipboard.
s = me.getSystem();
me.pasteClipboardData(s);
break;
} else if (sharedData && (s in sharedData)) {
me.doPaste(s, sharedData[s]);
break;
}
}
}
}
}
}
});
Ext.define('UserController', {
extend : 'Ext.app.ViewController',
alias: 'controller.users',
onBeforePaste:function(keyCode,event,grid){
//Perform custom logic
console.log(grid)
return false;
}
});
Ext.application({
name: 'Fiddle',
launch: function() {
var store = Ext.create('Ext.data.Store', {
fields: ['name', 'email', 'phone'],
data: [{
name: 'Lisa',
email: 'lisa#simpsons.com',
phone: '555-111-1224'
}, {
name: 'Bart',
email: 'bart#simpsons.com',
phone: '555-222-1234'
}, {
name: 'Homer',
email: 'homer#simpsons.com',
phone: '555-222-1244'
}, {
name: 'Marge',
email: 'marge#simpsons.com',
phone: '555-222-1254'
}]
});
Ext.create('Ext.grid.Panel', {
title: 'Simpsons',
store: store,
controller:'users',
width: 400,
renderTo: Ext.getBody(),
columns: [{
text: 'Name',
dataIndex: 'name'
}, {
text: 'Email',
dataIndex: 'email',
flex: 1
}, {
text: 'Phone',
dataIndex: 'phone'
}],
plugins: {
ptype: 'cellediting',
clicksToEdit: 2
},
selModel: {
type: 'spreadsheet',
rowNumbererHeaderWidth: 0
},
plugins: [{
ptype: 'clipboard',
listeners: {
beforepaste: 'onBeforePaste'
}
}],
listeners: {
selectionchange: function(grid, selection, eOpts) {
var store = grid.getStore();
}
}
});
}
});

Related

ExtJs - Checkbox selection model, disable checkbox per row and lose clearing all the selections

I have a grid with a checkbox selection model.
There are some rows that not be selectable, based on a value in a field. It's work.
My problem is that clearing all the selections by clicking the checkbox in the column header doesn't work.
On this link I see that costa was faced the same problem as me: ExtJs - Checkbox selection model, disable checkbox per row.
This listener is worked, but it's break checkbox clearing.
Code:
xtype: 'grid',
border: false,
selModel: {
selType: 'checkboxmodel',
listeners: {
beforeselect: function(grid, record) {
if (!record.get('supplier')) {
return false;
}
}
}
colums:[
....
],
....
Does anyone have an idea how to do this?
Thank you.
The header checkbox is checked only if all the records are checked. In your case it is impossible to check all the records => header checkbox will be never checked => it is impossible to uncheck.
To implement new logic, you can extend the checkbox model and write your own one with custom logic (by overriding the updateHeaderState method). Something like this:
Ext.define('CustomCheckboxModel', {
alias: 'selection.custom_checkboxmodel',
extend: 'Ext.selection.CheckboxModel',
allowDeselect: true,
updateHeaderState: function () {
// check to see if all records are selected
var me = this,
store = me.store,
storeCount = store.getCount(),
views = me.views,
hdSelectStatus = true,
selectedCount = 0,
selected, len, i;
if (!store.isBufferedStore && storeCount > 0) {
selected = me.selected;
hdSelectStatus = true;
store.each(function (record) {
if (!record.get('supplier')) {
return true;
}
var found = false;
for (i = 0, len = selected.getCount(); i < len; ++i) {
if (record.getId() == selected.getAt(i).id) {
found = true;
break;
}
}
if (!found) {
hdSelectStatus = found;
return false;
}
}, this);
}
if (views && views.length) {
me.column.setHeaderStatus(hdSelectStatus);
}
},
});
Ext.application({
name: 'Fiddle',
launch: function () {
var store = Ext.create('Ext.data.Store', {
fields: ['name', 'email', 'phone'],
data: [{
name: 'Lisa',
email: 'lisa#simpsons.com',
phone: '555-111-1224',
supplier: true
}, {
name: 'Bart',
email: 'bart#simpsons.com',
phone: '555-222-1234',
supplier: false
}, {
name: 'Homer',
email: 'homer#simpsons.com',
phone: '555-222-1244',
supplier: true
}, {
name: 'Marge',
email: 'marge#simpsons.com',
phone: '555-222-1254',
supplier: false
}]
});
Ext.create('Ext.grid.Panel', {
title: 'Simpsons',
store: store,
columns: [{
text: 'Name',
dataIndex: 'name'
}, {
text: 'Email',
dataIndex: 'email',
flex: 1
}, {
text: 'Phone',
dataIndex: 'phone'
}, {
xtype: 'checkcolumn',
text: 'Supplier',
dataIndex: 'supplier'
}],
height: 400,
renderTo: Ext.getBody(),
selModel: {
selType: 'custom_checkboxmodel',
listeners: {
beforeselect: function (selectionCheckboxModel, record, index, eOpts) {
console.log(record);
if (!record.get('supplier')) {
return false;
}
return true;
}
}
}
});
}
});

Not able to access object from data in ViewModel

Am trying to fetch the persondetails details into enableButton method.
Am aware that we can achieve this by simply adding key and value to data object.
But my question here is, is there any way to store data into persondetails and fetch it?
If I specify as below and bind accordingly, then its wok fine.
data: {
firstname: '',
lastname: ''
}
bind: {
value: '{lastname}'
},
Here is the code:
Ext.application({
name : 'Fiddle',
launch : function() {
Ext.define('MyApp.view.TestViewModel', {
extend: 'Ext.app.ViewModel',
alias: 'viewmodel.userinfo',
data: {
persondetails:{
firstname: '',
lastname: ''
}
},
formulas: {
enableButton: function(get){
debugger;
if(get('firstname')!=='' && get('lastname')!=='' ){
return true;
}else{
return false;
}
},
fullName: function(get){
if(get('firstname')!=='' && get('lastname')!=='' ){
return get('firstname') + ' ' + get('lastname');
}
}
}
});
Ext.create('Ext.form.Panel', {
title: 'Contact Info',
width: 500,
bodyPadding: 10,
renderTo: Ext.getBody(),
viewModel:{
type:'userinfo'
},
items: [{
xtype: 'textfield',
name: 'firstname',
emptyText: 'Enter First Name',
bind: {
value: '{persondetails.firstname}'
},
}, {
xtype: 'textfield',
name: 'lastname',
emptyText: 'Enter Last Name',
bind: {
value: '{persondetails.lastname}'
},
}, {
xtype: 'button',
reference: 'clickme',
disabled: true,
bind: {
disabled: '{!enableButton}'
},
text: 'Click',
listeners: {
click: function(){
alert('{fullName}');
}
}
}, {
xtype: 'displayfield',
fieldLabel: 'Full Name',
bind: {
value: '{fullName}'
}
}]
});
}
});
I have created a fiddle Example
According to documentation
When a direct bind is made and the bound property is an object, by
default the binding callback is only called when that reference
changes. This is the most efficient way to understand a bind of this
type, but sometimes you may need to be notified if any of the
properties of that object change.
To do this, we create a "deep bind":
In other words, if a object changes its properties, the viewmodel will not notify these changes (although their properties are changed correctly).
If you need to listen this changes, you need to use deep binding
Ext.application({
name : 'Fiddle',
launch : function() {
Ext.define('MyApp.view.TestViewModel', {
extend: 'Ext.app.ViewModel',
alias: 'viewmodel.userinfo',
data: {
persondetails: {
firstname: '',
lastname: ''
}
},
formulas: {
enableButton: {
bind: {
bindTo: '{persondetails}',
deep: true // listen to any change in personaldetails
},
get: function (data) {
return data.firstname && data.lastname
}
},
fullName: {
bind: {
bindTo: '{persondetails}',
deep: true // listen to any change in personaldetails
},
get: function (data) {
return data.firstname + ' ' + data.lastname
}
},
}
});
Ext.create('Ext.form.Panel', {
title: 'Contact Info',
width: 500,
bodyPadding: 10,
renderTo: Ext.getBody(),
viewModel:{
type:'userinfo'
},
items: [{
xtype: 'textfield',
name: 'firstname',
emptyText: 'Enter First Name',
bind: {
value: '{persondetails.firstname}'
},
}, {
xtype: 'textfield',
name: 'lastname',
emptyText: 'Enter Last Name',
bind: {
value: '{persondetails.lastname}'
},
}, {
xtype: 'button',
reference: 'clickme',
disabled: true,
bind: {
disabled: '{!enableButton}'
},
text: 'Click',
listeners: {
click: function(){
alert('{fullName}');
}
}
}, {
xtype: 'displayfield',
fieldLabel: 'Full Name',
bind: {
value: '{fullName}'
}
}]
});
}
});

filtering cards based on PortfolioItem selected for CardBoard

I am creating a rally sdk2 app, which shows Rally.ui.dialog.ChooserDialog of PortfolioItems like MMF, Epic and Program
When multiple MMFs or Epics or Programs are selected, show the features based on those filters, but cards are not getting. Something I am not able to figure out.
below is my some of the code
Ext.define('CustomApp', {
extend: 'Rally.app.App',
componentCls: 'app',
items:[{ xtype: 'container', itemId: 'filter_box', padding: 5},{xtype:'container',itemId:'button_box',layout:{type:'hbox'}, padding: 10}],
logger: new Rally.technicalservices.logger(),
launch: function() {
this.down('#button_box').add({
xtype: 'rallybutton',
text: 'Filter',
itemId: 'run-button',
scope: this,
handler: this._run,
margin: '0 10 0 95'
});
},
_drawCardBoard: function(records){
var filters = null;
alert("hi there");
console.log("context");
var me = this;
if (records[0].data.PortfolioItemTypeName == "MMF") {
console.log("context name", records[0].data.FormattedID);
filters = Ext.create('Rally.data.QueryFilter',{
property: 'Parent.FormattedID',
operator: '=',
value: records[0].data.FormattedID
});
} else if (records[0].data.PortfolioItemTypeName == "Epic") {
filters = Ext.create('Rally.data.QueryFilter',{
property: 'Parent.Parent.FormattedID',
operator: '=',
value: records[0].data.FormattedID
});
} else if (records[0].data.PortfolioItemTypeName == "Program") {
filters = Ext.create('Rally.data.QueryFilter',{
property: 'Parent.Parent.Parent.FormattedID',
operator: '=',
value: records[0].data.FormattedID
});
}
if (records.length > 1) {
for ( var i=1;i<records.length;i++ ) {
if (records[i].data.PortfolioItemTypeName == "MMF") {
console.log("context name 2", records[i].data.FormattedID);
filters = filters.or(Ext.create('Rally.data.QueryFilter',{
property: 'Parent.FormattedID',
operator: '=',
value: records[i].data.FormattedID
}));
} else if (records[i].data.PortfolioItemTypeName == "Epic") {
filters = filters.or(Ext.create('Rally.data.QueryFilter',{
property: 'Parent.Parent.FormattedID',
operator: '=',
value: records[i].data.FormattedID
}));
} else if (records[i].data.PortfolioItemTypeName == "Program") {
filters = filters.or(Ext.create('Rally.data.QueryFilter',{
property: 'Parent.Parent.Parent.FormattedID',
operator: '=',
value: records[i].data.FormattedID
}));
}
}
}
console.log("filters values", filters.toString());
this.cardboard = Ext.create('Rally.ui.cardboard.CardBoard',{
types: ['PortfolioItem/Feature'],
attribute: 'Release',
columnConfig: {
xtype: 'rallycardboardcolumn',
displayField: 'Name',
valueField: '_ref',
plugins: [
{ptype:'rallycolumndropcontroller'},
{ptype:'rallycardboardcardrecordprocessor'},
{ptype:'tscolumnheaderupdater'} /*,
{ptype:'tscolumnheaderupdater', field_to_aggregate: 'LeafStoryPlanEstimateTotal'}*/
],
},
storeConfig: {
filters: filters,
context: this.getContext().getDataContext()
},
cardConfig: {
showIconsAndHighlightBorder: false,
fields: [
'FormattedID',
'Name',
'Parent',
'ReleaseDate',
'ReleaseStartDate',
{ name: 'Project', renderer: me._renderProject },
{ name: 'PercentDoneByStoryPlanEstimate' },
{ name: 'c_FeatureEstimate', fetch: ['c_FeatureEstimate'] }
],
listeners: {
added: function(card,container){
me.logger.log(this,card,container);
},
fieldClick: function(eOpts) {
me.logger.log(this,eOpts);
if ( eOpts == "PercentDoneByStoryPlanEstimate" ) {
me._showDoneTooltip(eOpts,this);
}
}
}
}
});
_run: function() {
this._parents = {};
var me = this;
Ext.create('Rally.ui.dialog.ChooserDialog', {
width: 470,
autoScroll: true,
height: 500,
title: 'Select to Filter',
pageSize: 100,
closable: false,
selectionButtonText: 'Filter',
multiple: true,
artifactTypes: ['PortfolioItem/MMF','PortfolioItem/Epic', 'PortfolioItem/Program'],
autoShow: true,
storeConfig:{
fetch: ['Name','PortfolioItemTypeName', 'Parent']
},
listeners: {
scope: me,
artifactChosen: function(selectedRecord) {
console.log("selectedRecord", selectedRecord);
me._drawCardBoard(selectedRecord);
}
}
});
},

ExtJs - populating data from database to grid using actioncolumn

I have a grid with actionColumn and when I click on edit icon it should call the other form(already available) with data populated in to fields from database so that the user can edit and save it. I am new to Extjs please help
I tried with the following code but its not working:
myForm.getForm().load({
url: '/.RetrieveRecords',
params: { id: id},
method: 'POST',
waitMsg: 'Loading data...'
Here is my form1:
Ext.application({
name : 'extjs.com',
launch : function()
{
var myForm = Ext.create('Ext.form.Panel',
{
title: 'Registration Form',
id: 'form',
Layout: 'border',
border: 'true',
padding: 10,
bodyPadding: 30,
renderTo: Ext.getBody(),
defaultType: 'textfield',
items :
[
{fieldLabel: 'First Name', name: 'firstname', id: 'firstname',allowBlank: false, minLength: 2, maxLength:25, regex:/^[a-zA-Z]/},
{fieldLabel: 'Last Name', name: 'lastname', id: 'lastname', allowBlank: false, minLength: 2, maxLength:25},
{fieldLabel: 'Email', name: 'email', id: 'email',allowBlank: false, vType: 'email', msgTarget:'under'},
{fieldLabel: 'Mobile Number', name: 'mobilenumber', id: 'mobilenumber',allowBlank: false, minLength: 10, maxLength:10, regex:/^[7-9][0-9]{9}$/, regexText:"Invalid mobile number",msgTarget:"under"},
{
xtype: 'datefield',
fieldLabel: 'DOB'+'<span style="color:red;font-weight:bold" data-qtip="Required">*</span>',
name: 'dob',
id:'dob',
allowBlank: false,
value: '2 4 1978',
format: 'd m Y',
// value: new Date(),
maxValue: new Date(),
msgTarget:'side'
},
{
xtype:'radiogroup',
fieldLabel: 'Gender',
defaultType: 'radiofield',
anchor: '22.5%',
id:'gender1',
defaults:
{
flex: 1
},
layout: 'hbox',
items: [
{
boxLabel: 'Male',
name: 'rb',
inputValue: 'M',
checked: true
},
{
boxLabel: 'Female',
name: 'rb',
inputValue: 'F',
}]
},
{
xtype:'checkboxgroup',
fieldLabel: 'Known Technologies',
anchor: '50%',
id:'tech',
columns: 3,
vertical: true,
items:
[
{boxLabel: 'java', name: 'cb',inputValue: 'java', x:20, checked: true},
{boxLabel: 'c++', name: 'cb',inputValue: 'c++', x:20, checked: true},
{boxLabel: 'jsp', name: 'cb',inputValue: 'jsp', x:20, checked: false},
{boxLabel: 'javascript', name: 'cb',inputValue: 'javascript', checked: false},
{boxLabel: 'hadoop', name: 'cb',inputValue: 'hadoop', checked: false},
{boxLabel: 'spring', name: 'cb',inputValue: 'spring', checked: false}
]
},
{
xtype:'textarea',
fieldLabel: 'Hobbies',
name:'hobby',
id:'hobby',
anchor:'100%'
// padding:5
},
{
xtype:'fieldset',
title: 'Address',
collapsible:false,
items:
[
{
xtype:'combobox',
displayField:'cname',
valueField:'cid',
fieldLabel:'country'+'<span style =color:red;data-qtip="Required">*</span>',
queryMode:'local',
msgTarget: 'under',
name:'country',
id: 'country',
store: Ext.create('Ext.data.Store',{
fields:['cid','cname']
}),
listeners:
{
afterrender:function()
{
Ext.Ajax.request({
url:'./getRecords',
success: function(response)
{
var jarray = [];
jarray = Ext.JSON.decode(response.responseText);
Ext.getCmp('country').getStore().loadData(jarray);
},
failure: function(response)
{
Ext.Msg.alert('failed' + response.status);
}
});
},
change: function(a,b,c)
{
var countryID1 = Ext.getCmp('country').getValue();
Ext.Ajax.request({
url:'./getStates',
params:{countryID:countryID1},
success: function(response)
{
//alert(JSON.stringify(response));
var jarray = [];
jarray=Ext.JSON.decode(response.responseText);
Ext.getCmp('state').getStore().loadData(jarray);
},
failure: function(response)
{
Ext.Msg.alert('Failed' + response.status);
}
});
}
}
},
{
xtype:'combobox',
displayField:'sname',
valueField:'sid',
fieldLabel:'State',
name:'state',
id:'state',
queryMode:'local',
msgTarget: 'under',
store: Ext.create('Ext.data.Store',{
fields:['sid','sname']
}),
listeners:
{
change: function(a,b,c)
{
var StateID = Ext.getCmp('state').getValue();
Ext.Ajax.request({
url:'./getCities',
params: {StateID1:StateID},
success: function(response)
{
var jarray = [];
jarray = Ext.JSON.decode(response.responseText);
Ext.getCmp('city').getStore().loadData(jarray);
},
failure: function(response)
{
Ext.Msg.alert('failed' + response.status);
}
});
}
}
},
{
xtype:'combobox',
displayField:'cname',
valueField:'cid',
fieldLabel:'City',
name:'city',
id:'city',
queryMode:'local',
msgTarget: 'under',
store: Ext.create('Ext.data.Store',{
fields:['cid','cname','sid']
})
},
{
xtype:'textfield',
displayField:'PincodeName',
valueField:'pincodeID',
fieldLabel:'Pin-code',
id:'pincode',
allowBlank: false,
maskRe: /[0-9\-]/,
regex: /^[0-9]{3}(\-)?[0-9]{3}$/,
regexText:"invalid pincode",
msgTarget: 'under'
}
]
},
{
xtype:'fieldset',
title:'Education',
collasible: false,
items:
[
{
xtype:'combobox',
displayField:'QualificationName',
valueField:'QualificationID',
fieldLabel:'Qualification',
id:'qualification',
name:'qualification',
queryMode:'local',
msgTarget:'side',
store: Ext.create('Ext.data.Store',{
fields:['QualificationID','QualificationName'],
data:
[
{"QualificationID":"1","QualificationName":"B.Tech"},
{"QualificationID":"2","QualificationName":"Diploma"},
{"QualificationID":"3","QualificationName":"Advanced Diploma"}
]
}),
listeners:
{
change: function()
{
Ext.getCmp('DepartmentID').setVisible(true);
Ext.getCmp('PercentageID').setVisible(true);
}
}
},
{
xtype:'textfield',
name:'department',
id:'DepartmentID',
displayField:'Department',
valueField:'DeptID',
fieldLabel:'Department',
allowBlank: false,
hidden:true,
msgTarget: 'under'
},
{
xtype:'textfield',
name: 'percentage',
id: 'PercentageID',
displayField:'Percentage',
valueField:'PercentageID',
fieldLabel:'Percentage',
msgTarget: 'under',
regex:/^-?[0-9]{0,2}(\.[0-9]{1,2})?%?$|^-?(100)(\.[0]{1,2})?%?$/,
regexText:"invalid percentage",
hidden:true
}
]
}
],
buttons:
[
{text:'Submit',
handler: function()
{
var mail = Ext.getCmp('email').getValue();
var mnumber = Ext.getCmp('mobilenumber').getValue();
var gender = Ext.getCmp('gender1').getChecked()[0].inputValue;
var selection = [];
selection = Ext.getCmp('tech').getChecked();
var selections = "";
for(var i=0;i<selection.length;i++)
{
selections += selection[i].inputValue + " ";
}
var add = Ext.getCmp('country').getRawValue()+","+Ext.getCmp('state').getRawValue()+","+Ext.getCmp('city').getRawValue()+","+Ext.getCmp('pincode').getValue();
var edu = Ext.getCmp('qualification').getRawValue()+","+Ext.getCmp('DepartmentID').getValue()+","+Ext.getCmp('PercentageID').getValue();
var dob = Ext.getCmp('dob').getRawValue();
var hobby = Ext.getCmp('hobby').getValue();
var fname = Ext.getCmp('firstname').getValue();
var lname = Ext.getCmp('lastname').getValue();
//alert(this.up('form'));
var form = this.up('form').getForm();
if(form.isValid())
{
Ext.Ajax.request
({
url:'./Save_Records',
method: 'POST',
params: {mail1:mail,mnumber1:mnumber,gender2:gender,selections1:selections,add1:add,edu1:edu,dob1:dob,hobby1:hobby,fname1:fname,lname1:lname},
success: function(response)
{
Ext.Msg.alert("success" + response.status);
},
failure: function(response)
{
Ext.Msg.alert("failed" + response.status);
}
});
}
else
{
alert("Please fill in the form");
}
}
},
{
text:'Reset',
handler: function()
{
this.up('form').getForm().reset();
Ext.Ajax.request
({
url:'index.jsp',
method: 'POST',
success: function(response)
{
Ext.Msg.alert('Success' + " " + response.status);
},
failure: function(response)
{
Ext.Msg.alert('Failure' + " " + response.status);
}
});
}
}
]
});
}
});
Here is my Form2 with Actioncolumns:
Ext.onReady(function()
{
var store=Ext.create('Ext.data.Store',
{
autoload: true,
autosync: true,
data: [],
fields:
[
{name: 'firstname', id:'firstname'},
{name: 'email', id:'email'},
{name: 'mobileno', id:'mobileno'}
]
});
Ext.create('Ext.grid.Panel',
{
renderTo: Ext.getBody(),
height:150,
width:400,
x:200,
y:50,
store:store,
id: 'grid1',
columns:
[
{
header:'Firstname',
id:'firstname',
dataIndex:'firstname',
editor: {
xtype: 'textarea'
}
},
{
header:'Mobileno',
id:'mobileno',
dataIndex:'mobileno',
editor: {
xtype: 'textarea'
}
},
{
header:'Email',
id:'email',
dataIndex:'email',
editor: {
xtype: 'textarea'
}
},
{
header:'Action',
id:'action',
align:'center',
xtype:'actioncolumn',
sortable:false,
items:
[
{
icon:'images/view_icon.gif',
tooltip:'View',
handler: function(grid,rowIndex,colIndex)
{
var rec= grid.getStore().getAt(rowIndex);
}
},
{
icon:'images/edit_icon.gif',
tooltip:'Edit',
handler: function(grid,rowIndex,colIndex,e)
{
var rec= grid.getStore().getAt(rowIndex);
myForm.getForm().load({
// url: '/path/to/form/data',
params: { id: id},
method: 'POST',
waitMsg: 'Loading data...'
});
// Ext.Ajax.request(
// {
// url:'./RetrieveRecords',
// success: function(response)
// {
// Ext.Msg.alert("success" +" " + response.status);
// window.location.reload();
// },
// failure: function(response)
// {
// Ext.Msg.alert("failed" + response.status);
// }
// });
}
},
{
icon:'images/icons/cancel.png',
tooltip:'Delete',
handler: function(grid,rowIndex,colIndex)
{
var rec= grid.getStore().getAt(rowIndex);
var email = rec.get('email');
Ext.Ajax.request(
{
url:'./deleteRecords',
params:{email:email},
success: function(response)
{
Ext.Msg.alert("successfully deleted" +" " + response.status);
window.location.reload();
},
failure: function(response)
{
Ext.Msg.alert("failed" + response.status);
}
});
}
}
]
}
],
selType: 'cellmodel',
plugins:
[
Ext.create('Ext.grid.plugin.CellEditing',
{
clicksToEdit: 1
})
],
listeners:
{
afterrender:function()
{
Ext.Ajax.request(
{
params:{email:email},
url:'./RetrieveRecords',
success: function(response)
{
data = [];
data = Ext.JSON.decode(response.responseText);
Ext.getCmp('grid1').getStore().loadData(data);
},
failure: function(response)
{
Ext.Msg.alert("failure" + " " + response.status);
}
});
}
}
});
});
Try following as edit button:
handler: function(grid, rowIndex, colIndex, e) {
var rec = grid.getStore().getAt(rowIndex);
myForm.loadRecord(rec);
}

Live Search on Grid --ExtJs

I am new to ExtJs, and i am playing around to build logic to perform "live search" on Grid columns.
From the code below i am able to populate data into the grid but cannot make live search functionality. i am not sure where i am missing the logic.
Ext.define('abc.view.EmployeePanel', {
extend: 'Ext.window.Window',
alias: 'widget.EmployeePanel',
requires: [
'Ext.tab.Panel',
'Ext.form.*'],
constructor: function () {
this.callParent(arguments);
},
this. employeePopUPGridStore = new Ext.data.ArrayStore({
fields: [
{
name: 'empid',
type: 'number'
},
{
name: 'fname',
type: 'string'
},
{
name: 'lname',
type: 'string'
},
],
});
this.employeePopUPGridStore.loadData(localAr, false);
this.down('#addempgrid').bindStore(this.employeePopUPGridStore);
this.down('#addempgrid').getView().refresh();
},
items: [{
xtype:'textfield',
name:'search',
itemId:'search',
emptyText:'Search by First Name / Last Name',
listeners: {
onTextFieldChange: function(field, newValue, oldValue, eOpts){
var grid = field.down('addempgrid');
grid.store.clearFilter();
if (newValue) {
var matcher = new RegExp(Ext.String.escapeRegex(newValue), "i");
grid.store.filter({
filterFn: function(item) {
return matcher.test(item.get('empid')) ||
matcher.test(item.get('fname')) ||
matcher.test(item.get('job'));
}
});
}
}
}
},
{
xtype: 'gridpanel',
itemId: 'addempgrid',
autoHeight: true,
columns: [
{
header: "Employee ID",
flex: 1,
dataIndex: 'empid',
},
{
header: "Full Name",
flex: 3,
dataIndex: 'fname'
},
{
header: "LastName",
flex: 1,
dataIndex: 'lname'
},
]
}
] }
});
Any help around is much appreciated.
Hi Please try this way once..
{
xtype: 'textfield',
itemId: 'searchBar',
cls: 'search-bar',
width: 230,
margin: '0 0 0 10',
listeners: {
buffer: 250,
scope: this,
change: function (field, newVal) {
var grid = field.down('addempgrid');
grid.store.clearFilter();
if (newValue) {
var matcher = new RegExp(Ext.String.escapeRegex(newValue), "i");
grid.store.filter({
filterFn: function(item) {
return matcher.test(item.get('empid')) ||
matcher.test(item.get('fname')) ||
matcher.test(item.get('job'));
}
});
}
}
}
}
Hope it helps you

Resources