ExtJS 3.4 add button at the bottom of a grid - button

I'm new to ExtJS and try to add a button at the bottom of the grid. This button will open a modal dialog to select more persons. I don't know how to add this button after the grid. Do I have to use another component than GridPanel?
Can somebody help me?
The code looks like:
var selectedPersons = [
[1, 'Persnr', 'Name', 'Vorname']
];
var store = new Ext.data.ArrayStore({
fields: [
{name: 'PrsOid', type: 'int'},
{name: 'PersonalNr'},
{name: 'Nachname'},
{name: 'Vorname'}
]
});
store.loadData(selectedPersons);
var grid = new Ext.grid.GridPanel({
store: store,
columns:
[
{
id : 'PersonalNr',
header : 'PersonalNr',
width : 100,
sortable : true,
dataIndex: 'PersonalNr'
},
{
header : 'Nachname',
width : 100,
sortable : true,
dataIndex: 'Nachname'
},
{
header : 'Vorname',
width : 100,
sortable : true,
dataIndex: 'Vorname'
}
],
stripeRows: true,
autoExpandColumn: 'PersonalNr',
height: 200,
//width: 460,
title: 'Personenauswahl',
// config options for stateful behavior
stateful: true,
stateId: 'grid'
});
grid.render('gridSelectedPersons');

Do you mean something like a bottom bar ?
var grid = new Ext.grid.GridPanel({
store: store,
columns:
[
....
],
stripeRows: true,
autoExpandColumn: 'PersonalNr',
bbar: new Ext.Toolbar({
renderTo: document.body,
height: 30,
items: [
// begin using the right-justified button container
'->',
{
xtype:'button',
text:'The button',
//makes the button 24px high, there is also 'large' for this config
scale: 'medium'
}
]
})

Related

buffered store grid does not remember selection after scroll

I am using buffered store grid in extjs 4.1 after checking header checkbox all records get checked in view and if I scroll to the last and come back to first record my header checkbox and some rows get unchecked. i have used prunRemoved false on selection model. Please provide workaround for it. Thanks
my store for grid and grid:
var bufferedStore = Ext.create('Ext.data.Store', {
fields: ['key', 'fullName', 'text'],
buffered: true,
purgePageCount: null,
pageSize: 50,
leadingBufferZone: 200,
trailingBufferZone: 200,
proxy: {
type: 'direct',
directFn: diFn,
reader: {
type: 'json',
root: 'data',
totalProperty: 'total'
}
},
remoteFilter : true
});
var tabGridPanel = Ext.create('Ext.grid.Panel', {
itemId : _gridPanelId,
maxWidth: 478,
minWidth: 328,
width: 328,
maxHeigth : 150,
minHeight : 40,
rowLines: false,
store : _store,
id : panelId,
searchAllowed : _showSearch,
persistedSelections : {},
selModel: new Ext.selection.CheckboxModel({
allSelected : false,
allDeSelected : false,
mode : 'SIMPLE',
includeFuture : false,
pruneRemoved: false
}),
viewConfig: {
stripeRows: true,
deferEmptyText: false,
emptyText: ' No instance available',
listeners: {
'refresh': function(view, opt) {
var grid = mainPanel.queryById(_gridPanelId);
var store = view.getStore();
var selModel = grid.getSelectionModel();
var record = view.getStore().findRecord("text", "all",0, false, true, true);
if (!selModel.allSelected && selModel.isSelected(record))
selModel.deselect(record,true);
if (selModel.allSelected)
selModel.selectAll(true);
else if (selModel.allDeSelected)
selModel.deselectAll(true);
else{
for (var i in grid.persistedSelections) {
var index = store.findExact('fullName',i);
if (index != -1) {
grid.getSelectionModel().select(index,true,true);
}
}
}
},
'afterrender' : function() {
this.el.dom.style['overflow-x'] = 'hidden';
this.el.dom.style['overflow-y'] = 'auto';
}
}
},
columns: [{
dataIndex: 'fullName',
width : "92%",
menuDisabled: true,
sortable:false
}]
});
when i scroll normally selection remains but if i go directly to the end some rows get unchecked with header checkbox too.

jqGrid add class ui-state-disabled doesn't disable action

I am using jqGrid v 5.1.0 using the Bootstrap style. When I apply ui-state-disabled class to a pager button (add) the button looks disabled but when clicked it still processes the event. In previous version this use to disable the event as well. Using latest FF and IE. Any ideas? Thank you.
Edit - add snippet of code that initializes the grid (child). Notice second line from end where the add button is disabled. The button appears disabled but when clicked the event is executed.
Edit 2 - So after much pain and tears I create two fiddles. One demonstrates proper disabling of the edit button and Two is the same code but using Bootstrap. The edit button is not disabled.
// Water Source grid options...
var source_gridOptions = {
caption: 'Associated Water Source(s)',
data: sourceData,
datatype: 'local',
//url: "", // updated dynamically
//mtype: "GET",
styleUI : 'Bootstrap',
colModel: [
{ label: 'Source ID', name: 'ID', key: true, width: 28 },
{ label: 'Case ID', name: 'WATER_CASE_ID', width: 28, hidden: true },
{ label: 'Intake Name', name: 'INTAKE_SOURCE_NAME', width: 50 },
{ label: 'Intake Type', name: 'INTAKE_SOURCE_TYPE', width: 30 },
{ label: 'Source Type', name: 'SOURCE_TYPE', width: 20 },
{ label: 'Water Type', name: 'WATER_TYPE', width: 20 },
{ label: 'Notes', name: 'NOTES', width: 50 },
{ label: 'Verified', name: 'VERIFIED', width: 25 },
],
viewrecords: true,
height: 'auto',
width: initTabWidth, //dynamically set...
rowNum: 5,
pager: "#sourcePager",
gridComplete: function() {
} // end grid complete event
};
// define CRUD options...
var source_editOptions = {};
var source_addOptions = {};
var source_deleteOptions = {};
// init Water Source grid...
$("#sourceGrid").jqGrid(source_gridOptions).navGrid("#sourcePager",{edit:true,add:true,del:true,search:false},source_editOptions,source_addOptions,source_deleteOptions);
$("#add_sourceGrid").addClass('ui-state-disabled'); // <-- disable button
}); // end grid
Given your demo, I was able to figure it out. You actually need to add the ui-disabled class to work, not just disabled that you've added.
I've modified your fiddle here: http://jsfiddle.net/c6860ev8/16/
You can see in the jqGrid source file which classes are required for bootstrap integration here: https://github.com/tonytomov/jqGrid/blob/7901d7b7da969de1ca98282c60e335e013dc31ee/js/grid.base.js#L1035
Hope this helps!

ExtJs submit menubutton values

I am trying to submit the values from the menu buttons but know this is not possible and that I have to create a hidden field and store the button values there.
Being new to ExtJs I can not seem to figure out how to do this. Below is the basic layout I used to check the button shows and I can choose a colour.
getFormItems : function() {
var me = this;
return [{
xtype : "fieldset",
title : "Items to monitor",
defaults : {
labelSeparator : ""
},
items : [{
xtype : "checkbox",
name : "cpuenable",
boxLabel : _("Will monitor CPU Temperature"),
fieldLabel : _("CPU Temperature"),
checked : false
},{
xtype : 'hiddenfield',
id : 'buttonvalues'
},{
xtype : "button",
name : "colours",
text : _("Choose Colours"),
scope : this,
style : {
marginTop : "10px",
marginBottom : "10px"
},
menu: [{
text: "Main CPU Colour",
menu: {
xtype : "colormenu",
name : "colourc",
value : "000000",
cls : "menubutton-class",
handler: function (obj, rgb) {
var colourmField = this.findField('colourc');
colourmField.setValue(rgb.toString());
alert(colourmField.getValue());
}
}
},{ and so on
Okay, here is an edit for you of my previous post. I give you an example how to fetch all child components you want inside a component:
Example extjs:
{
xtype: 'fieldset',
id: 'fsButtons',
items: [
{
xtype: 'hiddenfield',
id: 'hiddenValues'
},
{
xtype: 'button'
color: '000000'
},
{
xtype: 'button'
color: '555555'
}
]
}
Function to fill the hiddenfield:
function getButtonVars() {
var buttonVars = new Array();
//Get all components with xtype 'button' inside the fieldset with id 'fsButtons'
Ext.Array.each(Ext.ComponentQuery.query('button', Ext.getCmp('fsButtons'), function(button){
buttonVars.push(button.color);
});
Ext.getCmp('hiddenValues').setValue(buttonVars.join(',')); // concats all button values to one string: '000000,555555' etc.
}
I hope it's clear now :)
http://docs-origin.sencha.com/extjs/4.2.2/#!/api/Ext.ComponentQuery

Change Background Row Color when Press a Button

i just want to change the default background color of a grid row after it had been selected and when i press a button. I'm using sencha extjs 4.2.
Anyone could help me please?
Thank you in advance
Task can be solved using column renderer: http://jsfiddle.net/bLgSA/10/
var button = Ext.create('Ext.button.Button', {
text: 'btn',
listeners: {
click: function() {
var sm = grid.getSelectionModel();
if (sm.hasSelection()) {
var rec = sm.getSelection()[0];
if (rec.get("color") == "black")
rec.set("color", "red");
else
rec.set("color", "black");
}
}
}
});
var renderer = function(value, metaData, record) {
metaData.style = 'color:'+record.get("color");
return value;
}
var grid = Ext.create('Ext.grid.Panel', {
height: 300,
width: 400,
title: 'hello',
columns: [
{text: 'c1', dataIndex: 'id', renderer: renderer},
{text: 'c2', dataIndex: 'label', renderer: renderer}
],
store: Ext.create('Ext.data.Store', {
fields: ['id', 'label', 'color'],
data: [
{id: 0, label: 'a', color: 'black'},
{id: 1, label: 'b', color: 'red'}
]
})
});
grid.render(Ext.getBody());
button.render(Ext.getBody());
This is the way to select a one row at a time and highlight as selected row to add css class
function rowHighlight()
{
$('#facCodes tr').click(function(event){
$(this).addClass("click").siblings().removeClass("click");
});
}

ExtJS4 - How to add file upload editor in Grid?

I want to create Grid that has 3 columns. One column is 'textfield' and the other two columns are image which I set editor as 'filefield'. On image column I can display image by using renderer but when it comes to edit or add new image I can't press the browse button to browse image. Here is my code.
var grid = Ext.create('Ext.grid.Panel', {
title: 'Author',
store: Ext.data.StoreManager.lookup('authorStore'),
renderTo: 'authorGrid',
columns: [{
header: 'Name',
dataIndex: 'name',
editor: {
xtype: 'textfield',
}
}, {
header: 'Icon',
dataIndex: 'iconImage',
renderer: function(val) {
return '<img src="' + val + '">';
},
editor: {
xtype: 'filefield',
allowBlank: false,
}
}, {
header: 'Background',
dataIndex: 'background',
renderer: function(val) {
return '<img src="' + val + '">';
},
editor: {
xtype: 'filefield',
allowBlank: false,
}
}],
selModel: Ext.create('Ext.selection.CheckboxModel'),
plugins: [
Ext.create('Ext.grid.plugin.CellEditing', {
clicksToEdit: 2
})
],
tbar: [{
iconCls: 'icon-add',
text: 'Add',
handler: function() {
// add record
}
}, {
iconCls: 'icon-delete',
text: 'Remove',
handler: function() {
// remove selected records...
}
}, {
iconCls: 'icon-save',
text: 'Save',
handler: function() {
store.save();
}
}]
});
What does it wrong? Can I put 'filefield' editor like this? Is it possible to click save button on grid for save grid data and upload images?
After quick investigation I didn't realized any easy solutions for this issue. In my view EditorGrid isn't supposed to support such type of operations.
And moreover - editor in grid is intended to modify value in corresponding row of the store. With fileupload you operate with files, but as I see in you code you are waiting for a string data in these cells.
What I suggest is replace the fileupload in cells with a popup. When user clicks a cell, you will open popup with fileupload. When they select a file and upload it - you close the popup and reload record in grid's store. Just an idea!

Resources