Change text filed attribute in a specific row dojo dgrid in edit mode - dojo

I want to change a text field attribute in a specific row.
I have an editable dGrid with 5 fields, 2 of them are disabled and their values change when a select filed value is changed, now I want when the value of the select is changing to specific value, the two disabled filed are enabled for edit only for this row, and then be disabled again when choosing other values in the select, here's a screenshot of the grid
And here's the creation of the grid
this.productStore = new Memory({idProperty: 'id', data: []});
this.productObjStore = new ObjectStore({objectStore:
this.productStore});
var productColumn = {
field: 'productServiceId',
label: dojoConfig.i18n.productOrService,
className: 'hand',
editor: Select,
autoSave: true,
editorArgs: {
searchAttr: 'name',
labelAttr: "name",
style: 'width: 95%',
store: this.productObjStore,
required: true,
},
renderCell: function(object, data, td, options){
if(data != ''&& data != dojoConfig.i18n.addNewProduct){
td.innerHTML = this.editorArgs.store.get(data).label;
}
}
};
var quantityColumn = {
field: 'quantity',
label: dojoConfig.i18n.quantity,
className: 'hand',
editor: TextBox,
autoSave: true,
editorArgs: {
placeHolder: '#####',
regExp: dojoConfig.regExps.intExp,
trim: true,
style: 'width: 100%',
invalidMessage: dojoConfig.i18n.error_quantityIsZero,
validator: function(){
if( this.value > 0)
return true;
return false;
}
}
};
var me=this
var rateColumn = {
field: 'rate',
label: dojoConfig.i18n.rate,
className: 'hand',
editor: TextBox,
autoSave: true,
editorArgs: {
disabled: true,
placeHolder: '#####.##',
regExp: dojoConfig.regExps.floatExp,
trim: true,
style: 'width: 100%',
}
};
var amountColumn = {
field: 'amount',
label: dojoConfig.i18n.amount,
className: 'hand',
editor: TextBox,
editorArgs: {
disabled: true,
placeHolder: '#####.##',
regExp: dojoConfig.regExps.floatExp,
trim: true,
style: 'width: 100%',
}
};
this.discountStore = new Memory({idProperty: 'id', data: []});
var discountColumn = {
field: 'discount',
label: dojoConfig.i18n.lineDiscount,
className: 'hand',
editor: Select,
autoSave: true,
editorArgs: {
searchAttr: 'name',
labelAttr: "name",
style: 'width: 99%',
store: this.discountStore,
required: false,
value:null
},
renderCell: function(object, data, td, options){
if(data != '')
td.innerHTML = this.editorArgs.store.get(data).label;
}
};
this._grid = new Grid({
autoHeight: true,
showToolbar: true,
//label: dojoConfig.i18n.invoiceLines,
style: 'width: 100%; max-height: 200px; margin-top: 1px;',
columns : [
{field: 'id', label: 'ID', hidden: true, unhidable: true},
productColumn,
{field: 'description' ,label: dojoConfig.i18n.description, dismissOnEnter: false, editor: 'textarea', autoSave: true, renderCell: function(object, data, td, options){
td.innerHTML = data;
}},
quantityColumn,
rateColumn,
// discountColumn,
amountColumn,
{field: 'taxable', style:'width:50%', label: dojoConfig.i18n.taxable, editor: CheckBox, hidden: true, unhidable: true}
],
contextMenuInfo: [
{label: dojoConfig.i18n.new_, iconClass: 'newIcon', onClick: this.addProduct},
{label: dojoConfig.i18n.remove, iconClass: 'deleteIcon', onClick: this.deleteProduct, needSelection: true}
],
contextHandler: this,
selectionMode : 'single', // for Selection; only select a single row at a time
cellNavigation : false,
colspan: 5
});
this._grid.set('store', new Observable(new Memory({idProperty: 'id', data: []})));
Thanks

Related

Auto serial number column to jqxgrid

How to add auto serial number column to jqxgrid when database records are in random order and
there is no specific field in database for serial number of records or
in case we are only dealing with a subset of records from a table?
Add this in your column describing area
{
text: 'Srl No', sortable: false, filterable: false, editable: false,
groupable: false, draggable: false, resizable: false,
datafield: '', columntype: 'number', width: 50,
cellsrenderer: function (row, column, value) {
return "<div style='margin:4px;'>" + (value + 1) + "</div>";
}
},
Then your Grid code look like below
<script type="text/javascript">
$(document).ready(function () {
// prepare the data
var data = MyJsonData;
var source =
{
localdata: data,
datatype: "json",
datafields:
[
{ name: 'firstname', type: 'string' },
{ name: 'lastname', type: 'string' }
]
};
var dataAdapter = new $.jqx.dataAdapter(source);
$("#jqxgrid").jqxGrid(
{
width: 300,
source: dataAdapter,
columnsresize: true,
columns: [
{
text: 'Srl No', sortable: false, filterable: false, editable: false,
groupable: false, draggable: false, resizable: false,
datafield: '', columntype: 'number', width: 50,
cellsrenderer: function (row, column, value) {
return "<div style='margin:4px;'>" + (value + 1) + "</div>";
}
},
{ text: 'Name', datafield: 'firstname', width: 125 },
{ text: 'Last Name', datafield: 'lastname', width: 125 }
]
});
});
</script>
Grid Cells Rendering alongwith following code will help
{ text: 'Serial Number', dataField: '', columntype: 'number', width: 50,cellsrenderer: slrenderer },
In order to render we
var slrenderer = function (value) {
value=value+1; // default numbering starts at 0
return '<div style="text-align: center; margin-top: 5px;">' + value + '</div>';
}

Set the edited row in EXTJS grid after editing without refreshing page

I am editing a row in EXTJS grid on clicking the edit action link. On clicking the edit link of a row a new window opens with all the data of the row and "Save" and "Cancel" button.
On clicking the "Save" button, it is saving the record in database. But I want the row should also get refreshed without refreshing the page.
I am new to EXTJS.
Can any one help me to do the same.
Here is my code.
Ext.require([
'Ext.grid.*',
'Ext.data.*',
'Ext.util.*',
'Ext.grid.plugin.BufferedRenderer'
]);
Ext.define('TestResult', {
extend: 'Ext.data.Model',
fields: [
{
name: 'ID',
type: 'int'
},
{
name: 'jobNo',
type: 'int'
},
{
name: 'stageCode',
type: 'String'
},
{
name: 'productTitle',
type: 'String'
},
{
name: 'brand',
type: 'String'
},
{
name: 'category',
type: 'String'
},
{
name: 'ftpDate',
type: 'Date'
}],
idField: 'ID'
});
Ext.onReady(function() {
var store = Ext.create('Ext.data.Store', {
model: 'TestResult',
autoLoad: true,
autoSync: true,
proxy: {
type: 'ajax',
url : 'data.jsp',
reader :
{
type : 'json'
},
writer :
{
type : 'json'
}
}
});
var grid = Ext.create('Ext.grid.Panel', {
width: 700,
height: 500,
title: 'Buffered Grid of records',
store: store,
loadMask: true,
plugins: 'bufferedrenderer',
selModel: {
pruneRemoved: false
},
viewConfig: {
trackOver: false
},
features: [{
ftype: 'groupingsummary',
groupHeaderTpl: 'Department: {name}',
showSummaryRow: false
}],
// grid columns
columns:[{
text: 'ID',
sortable: true,
dataIndex: 'ID',
groupable: false,
locked: true,
width: 70
}, {
text: 'Job No.',
sortable: true,
dataIndex: 'jobNo',
groupable: false,
locked: true,
width: 120
}, {
text: 'Version',
dataIndex: 'stageCode',
groupable: false
}, {
text: 'Product Title',
dataIndex: 'productTitle',
groupable: false
}, {
text: 'Brand',
dataIndex: 'brand',
groupable: false
}, {
text: 'Category',
dataIndex: 'category',
width: 200,
groupable: false
}, {
text: 'FTP Date',
dataIndex: 'ftpDate',
xtype: 'datecolumn',
groupable: false
},
{
xtype:'actioncolumn',
header:'Edit',
width:50,
items: [{
icon: 'assets/images/edit.png', // Use a URL in the icon config
tooltip: 'Edit',
handler: function(grid, rowIndex, colIndex) {
var rec = grid.getStore().getAt(rowIndex);
editForm.show();
editForm.down('form').loadRecord(rec);]
}],
renderTo: Ext.getBody()
});
var editForm = new Ext.Window({
title: 'Edit Window',
items:[
{
xtype: 'form',
url: 'UpdateController',
items: [
{
xtype: 'hidden',
fieldLabel: 'ID',
name: 'ID',
allowBlank: false,
readOnly: true
},
{
xtype: 'textfield',
fieldLabel: 'Job No.',
name: 'jobNo',
allowBlank: false,
readOnly: true
},
{
xtype: 'textfield',
fieldLabel: 'Version',
name: 'stageCode',
allowBlank: false,
readOnly: true
},
{
xtype: 'textfield',
fieldLabel: 'Product Title',
name: 'productTitle',
allowBlank: false
},
{
xtype: 'textfield',
fieldLabel: 'Category',
name: 'category',
allowBlank: false
},
{
xtype: 'textfield',
fieldLabel: 'Brand',
name: 'brand',
allowBlank: false
},
{
xtype: 'datefield',
fieldLabel: 'FTP Date',
name: 'ftpDate',
allowBlank: false
}],
buttons : [{
text : 'Save',
handler: function()
{
this.up('form').getForm().submit(
{
success: function(f,a)
{
store.save();
var win = Ext.WindowManager.getActive();
if (win)
{
win.hide();
}
},
failure: function(f,a)
{
//Ext.Msg.alert('Warning', 'Error');
Ext.Msg.alert('Warning', a.result.errormsg);
this.up('window').hide();
}
});
}
},
{
text: 'Cancel',
handler: function()
{
this.up('window').hide();
}
}]
}
]
});
});
Thanks
In your this.up('form').getForm().submit success handler you can update record, which you loaded into form, by using Ext.form.Basic updateRecord method.
So just add into success handler code:
// update record with form data
f.updateRecord();
// mark record as synchronized with server (because you already sent data to server with form submit method)
f.getRecord().commit();

ExtJs:Show Grid after Button is clicked

I have a form in which the values for the Grid is populated as soon as the Form is displayed.But i need to populate the grid after the button is clicked based on text box values.
ExtJs:
var url = location.href.substring(0,location.href.indexOf('/', 14));
var grid;
var store;
var userStore;
Ext.onReady(function(){
var rowEditing = Ext.create('Ext.grid.plugin.RowEditing');
Ext.define('userList', {
extend: 'Ext.data.Model',
fields: [{ name: 'id', mapping: 'id' },
{ name: 'name', mapping: 'name' },
{ name: 'firstName' ,mapping:'personalInfo.firstName'},
{ name: 'lastName' ,mapping:'personalInfo.lastName'},
{ name: 'gender' ,mapping:'personalInfo.gender'},
{ name: 'email' ,mapping:'personalInfo.address.email'}
]
});
store = Ext.create('Ext.data.Store', {
model: 'userList',
autoLoad: true,
proxy: {
type: 'ajax',
url : url+'/lochweb/loch/users/getUser',
reader: {
type: 'json',
root: 'Users'
}
}
});
function swapStrore(){
//userStore = store;
userStore = Ext.create('Ext.data.Store', {
model: 'userList',
autoLoad: true,
proxy: {
type: 'ajax',
url : url+'/lochweb/loch/users/getUser',
reader: {
type: 'json',
root: 'Users'
}
}
});
Ext.getCmp('userGrid').getView().refresh();
return userStore;
}
function updateUsers(id){
window.location = url+'/lochportal/createUser.do';
}
var searchUsers = new Ext.FormPanel({
renderTo: "searchUsers",
frame: true,
title: 'Search Users',
bodyStyle: 'padding:5px',
width: 900,
items:[{
xtype:'textfield',
fieldLabel: 'Username',
name: 'userName'
},{
xtype:'textfield',
fieldLabel: 'First Name',
name: 'firstName'
},{
xtype:'textfield',
fieldLabel: 'Last Name',
name: 'lastName'
},
{
xtype: 'button',
text: 'Search',
listeners: {
click: function(){
Ext.Ajax.request({
method:'GET',
url : url+'/lochweb/loch/users/getUser',
params : searchUsers.getForm().getValues(),
success : function(response){
//console.log(response);
//swapStrore();
}
});
}
}
},{
xtype: 'button',
text: 'Cancel',
listeners: {
click: function(){
window.location = url+'/lochportal/viewSuccessForm.do';
}
}
},
grid = Ext.create('Ext.grid.Panel', {
//plugins: [rowEditing],
id:'userGrid',
width: 900,
height: 300,
frame: true,
store: store,
iconCls: 'icon-user',
columns: [{
text: 'ID',
width: 40,
sortable: true,
dataIndex: 'id'
},
{
text: 'Name',
flex: 1,
sortable: true,
dataIndex: 'name',
field: {
xtype: 'textfield'
}
},
{
text: 'FirstName',
flex: 1,
sortable: true,
dataIndex: 'firstName',
field: {
xtype: 'textfield'
}
},
{
text: 'LastName',
flex: 1,
sortable: true,
dataIndex: 'lastName',
field: {
xtype: 'textfield'
}
},
{
text: 'Gender',
flex: 1,
sortable: true,
dataIndex: 'gender',
field: {
xtype: 'textfield'
}
},
{
text: 'Email',
flex: 1,
sortable: true,
dataIndex: 'email',
field: {
xtype: 'textfield'
}
},
{
xtype: 'actioncolumn',
width: 50,
items:[{
icon : '/lochportal/extJS/resources/themes/images/access/window/edit.gif', // Use a URL in the icon config
tooltip: 'Sell stock',
handler: function(grid, rowIndex, colIndex) {
var rec = store.getAt(rowIndex);
//alert("Sell " + rec.get('id'));
updateUsers(rec.get('id'));
}
}]
}]
})]
});
var win = new Ext.Window({
layout:'fit',
closable: false,
resizable: true,
plain: true,
border: false,
items: [searchUsers]
});
win.show();
});
How to populate the grid after search button is clicked?
Thanks
Use bindStore() method of the grid to assign new or different store to grid which is already displayed. If you want to first show an empty grid - either filter all records out or assign store property to null initially.

Grid for Update Entries

I did the following code to list the searched items in the grid.
Ext.onReady(function(){
var rowEditing = Ext.create('Ext.grid.plugin.RowEditing');
var searchUsers = new Ext.FormPanel({
renderTo: "searchUsers",
frame: true,
title: 'Search Users',
bodyStyle: 'padding:5px',
width: 500,
items:[{
xtype:'textfield',
fieldLabel: 'Username',
name: 'userName'
}],
buttons:[
{
text:'Search',
formBind: true,
listeners: {
click: function(){
Ext.Ajax.request({
method:'GET',
url : url+'/lochweb/loch/users/getUser',
params : searchUsers.getForm().getValues(),
success : function(response){
console.log(response); //<--- the server response
Ext.define('userList', {
extend: 'Ext.data.Model',
fields: [{ name: 'id', mapping: 'id' },
{ name: 'name', mapping: 'name' },
{ name: 'firstName' ,mapping:'personalInfo.firstName'},
{ name: 'lastName' ,mapping:'personalInfo.lastName'}
]
});
var store = Ext.create('Ext.data.Store', {
model: 'userList',
autoLoad: true,
proxy: {
type: 'ajax',
url : url+'/lochweb/loch/users/getUser',
reader: {
type: 'json',
root: 'Users'
}
}
});
var grid = Ext.create('Ext.grid.Panel', {
renderTo: "searchUsers",
plugins: [rowEditing],
width: 900,
height: 300,
frame: true,
title: 'Users',
store: store,
iconCls: 'icon-user',
columns: [{
text: 'ID',
width: 40,
sortable: true,
dataIndex: 'id'
},
{
text: 'Name',
flex: 1,
sortable: true,
dataIndex: 'name',
field: {
xtype: 'textfield'
}
},
{
text: 'FirstName',
flex: 1,
sortable: true,
dataIndex: 'firstName',
field: {
xtype: 'textfield'
}
},
{
text: 'LastName',
flex: 1,
sortable: true,
dataIndex: 'lastName',
field: {
xtype: 'textfield'
}
}]
});
}
});
}
}
}
]
});
var win = new Ext.Window({
layout:'fit',
closable: false,
resizable: true,
plain: true,
border: false,
items: [searchUsers]
});
win.show();
});
How to Fit the grid inside the Search User window
Add an icon in the grid,so that by clicking on that icon the values from the
grid must be populated to entry form for update.
Here with your code, I've found something:
Use renderTo: "searchUsers" for both FormPanel and the Grid: You add the FormPanel to the window, so this config should not exist (Please refer to renderTo document). So remove them.
Use frame: true for both FormPanel and the Grid: There you have the window as container, so the Form and Grid have been framed inside. So remove them.
You dynamically add the Grid on searching: I recommend you create the result Grid as a separate component (not inside success's result) and specify both Form and Grid as items' components of window. You still can config the Grid with hidden. When Ajax is successful, you can fill the Grid with data returned and show it.
"add an icon in the grid": You can specify a new column in columns of the Grid and use renderer config of grid panel to show the button. For example:
renderer: function(v) {
return "<input type='button'.../>";
}
Finally, you can catch the itemclick event of the grid to know if the column of the clicked cell is the cell which contains the button, the entry will be populated to somewhere you want. Don't forget to specify the grid's Selection model as cellmodel

Combo Box In Extjs 4

my combo boxes are not displaying when i click on add occurs a new row but it shows "Uncaught TypeError: Cannot read property 'xtype' of undefined" error every time and not showing the combo box.please help me to solve this problem.it works fine in extjs 3 but i am currently working on extjs 4
var cond1 = Ext.create('Ext.data.Store', {
fields: ['maint_condition1'],
data : [
['Excellent'],['Poor'],['New'],['good'],['scrap']
]
}
);
var cond2 = Ext.create('Ext.data.Store', {
fields: ['maint_condition2'],
data : [
['Excellent'],['Poor'],['New']
]
}
);
var cond3 = Ext.create('Ext.data.Store', {
fields: ['maint_condition3'],
data : [
['New'],['Excellent']
]
}
);
var cond4 = Ext.create('Ext.data.Store', {
fields: ['maint_condition4'],
data : [
['New'],['Excellent'],['good'],['Poor'],['scrap']
]
}
);
//ready store
//var cb_select2 =new Ext.grid.CheckboxSelectionModel();
//var cb_select2 =new Ext.grid.CheckboxSelectionModel();
var asset_edit = new Ext.form.TextField();
var notes_edit = new Ext.form.TextField();
var date_edit = new Ext.form.DateField({format: 'm/d/Y'});
var rowEditing = Ext.create('Ext.grid.plugin.RowEditing', {
clicksToMoveEditor: 1,
autoCancel: false,
saveText: 'Save',
listeners: {
afteredit: syncStore
}
});
var cond1_edit = new Ext.form.DateField({format: 'combo'});
//var sm = Ext.grid.getSelectionModel();
//Grid for show data
var grid = Ext.create('Ext.grid.Panel', {
renderTo: document.body,
//renderTo: 'grid1',
extend: 'Ext.form.ComboBox',
plugins:[rowEditing],
frame: true,
height:140,
width:950,
enableColumnMove: false,
store: store,
columns: [
{header: "Asset ID", dataIndex: 'asset_id',readOnly: true},
{header: "Maint. ID", dataIndex: 'id',readOnly: true},
{header: "Date", dataIndex: 'date_',xtype: 'datecolumn',width: 90,
editor: {
xtype: 'datefield',
allowBlank: false,
format: 'm/d/Y',
minValue: '01/01/2006',
minText: 'Cannot have a start date before the company existed!',
maxValue: Ext.Date.format(new Date(), 'm/d/Y')
}
},
{header: "Notes", dataIndex: 'notes',editor: notes_edit},
{header: "Maint_condition1", dataIndex: 'maint_condition1', sortable: true,width: 120,
editor: Ext.create('Ext.form.ComboBox', {
xtype:'combobox',
allowBlank: false,
mode: 'local',
store: cond1,
valueField: 'maint_condition1',
displayField: 'maint_condition1',
triggerAction: 'all',
editable: false
}
)},
{header: "Maint_condition2", dataIndex: 'maint_condition2', sortable: true,width: 120,
editor: Ext.create('Ext.form.ComboBox', {
xtype:'combobox',
allowBlank: false,
mode: 'local',
store: cond2,
valueField: 'maint_condition2',
displayField: 'maint_condition2',
triggerAction: 'all',
editable: false
}
)},
{header: "Maint_condition3", dataIndex: 'maint_condition3', sortable: true,width: 120,
editor: Ext.create('Ext.form.ComboBox', {
xtype:'combobox',
allowBlank: false,
mode: 'local',
store: cond3,
valueField: 'maint_condition3',
displayField: 'maint_condition3',
triggerAction: 'all',
editable: false
}
)},
{header: "Maint_condition4", dataIndex: 'maint_condition4', sortable: true,width: 120,
editor: Ext.create('Ext.form.ComboBox', {
xtype:'combobox',
allowBlank: false,
mode: 'local',
store: cond4,
valueField: 'maint_condition4',
displayField: 'maint_condition4',
triggerAction: 'all',
editable: false
}
)}
],
tbar: [
{
text: 'Add Record',
icon: 'http://localhost/toolbar2/app/webroot/images/table_add.png',
cls: 'x-btn-text-icon',
handler: function()
{
rowEditing.cancelEdit();
var r = Ext.create('User', {
id: 0,
notes: 'New Notes',
asset_id: window.id,
});
store.insert(0, r);
rowEditing.startEdit(0,0);
}
},
{
text: 'Remove Record',
icon: 'http://localhost/toolbar2/app/webroot/images/table_delete.png',
cls: 'x-btn-text-icon',
handler: function() {
var sm = grid.getSelectionModel();
rowEditing.cancelEdit();
store.remove(sm.getSelection());
if (store.getCount() > 0)
{
sm.select(0);
}
}
}]
});
As I mentioned on my last comment on your other question - you need to define datatypes in the store - aka the xtype. Your code won't just know the items are strings unless you implicit define it.