How to get value of other column in renderer function in Extjs? - extjs

I want to get the value of another column in the same row, in a renderer function of one column. I tried a method, but it didn't work. And here's my code:
columns: [
{id:'id',header: 'ID', width: 30, sortable: true, dataIndex: 'category_id'},
{header: 'current_level', width: 100, sortable: true, dataIndex: 'current_level'},
{header: 'complete_code', width: 100, sortable: true, dataIndex: 'complete_code'},
{header: 'parent_id', width: 100, sortable: true, dataIndex: 'parent_id'},
{header: 'parent_name', width: 100, sortable: true, dataIndex: 'parent_name'},
{
header: 'has_standards', width: 100, sortable: true, dataIndex: 'has_standards',
renderer: function(val, meta, record, rowIndex) {
if (val == 'Yes') {
console.log(record.data.category_id);
}
}
}
],
As you see, I want to get the category_id in the same row, in the renderer function of has_standards column. But my way is wrong. Could you tell me how to do it?

You want to use record.get('category_id') e.g.:
renderer: function(val, meta, record, rowIndex) {
if (val === 'Yes') {
console.log(record.get('category_id'));
}else{
console.log('Value is not "Yes"');
}
}

I am using Ext JS 6 (Sencha) and I wanted to display an image in a grid column based on whether the value of another column in the same grid was of a certain value. I followed SW4's solution with some minor changes as per the version of Ext JS I am using and it worked great. Thank you.
Ext.define('ViewLL.view.main.List', {
extend: 'Ext.grid.Panel',
xtype: 'list',
requires: ['App.store.Datastore'],
store: {type: 'datastore'},
columns: [
{ text: 'Market',
renderer: function(value, metaData, record, rowIndex) {
var value = record.get('location');
if (value == NYC) {
return '<img src="resources/images/bigApple.jpg"/>';
}
else {
return null;
}
}
},
{ text: 'City', dataIndex: 'location' }
]
This displays the image file in a grid column when the City column's has a record, the value of which is NYC. For all other records it displays a blank cell.

Related

ExtJS 6 -- autofit grid column header text

Is there a way I can set the columns width to match the width of the column text? The user can resize the columns to see the content if needed, but I want the full header text to be showing at least, even if the column content isnt.
thanks
Yes it should be possible. You can call the method autoSize() on the column.
You can combine it with the minWidth and maxWidth.
I have found this example on the Sencha forums for Ext 4.2 so it should be very similar for Ext 6.2:
Ext.create('Ext.grid.Panel', {
title: 'Simpsons',
store: Ext.data.StoreManager.lookup('simpsonsStore'),
columns: [
{ text: 'Name', dataIndex: 'name', width: 150, autoSizeColumn: true },
{ text: 'Email', dataIndex: 'email', width: 150, autoSizeColumn: true, minWidth: 150 },
{ text: 'Phone', dataIndex: 'phone', width: 150 }
],
viewConfig: {
listeners: {
refresh: function(dataview) {
Ext.each(dataview.panel.columns, function(column) {
if (column.autoSizeColumn === true)
column.autoSize();
})
}
}
},
width: 450,
renderTo: Ext.getBody()
});

How to create editable grid column with few values? | Extjs

I have a grid with columns name, value, new value. New value column is combobox because there can be a few values. Admin can approve/decline new values and correct proposed these new values.
My grid columns looks like this:
columns: [
{ text: 'Name', dataIndex: 'property_name', width: 300 },
{ text: 'Value', dataIndex: 'value', width: 350 },
{
text: 'New Value',
dataIndex: 'new_value',
width: 350,
editor: { allowBlank: true },
renderer: function(value, cell, record){
return record.get('new_value') == record.get('value') ? '' : record.get('new_value');
}
},
],
So is there a way to achive functionality a described above?
The editor configuration takes any Ext.form.Field configuration (default is textfield), so for example:
editor:{
xtype:'combobox', // <- this tells
store:'MyNewValueStore',
forceSelection:true,
queryMode:'local',
...
}

uncheck selected checkbox from check all in ext.js

I have grid panel, its having check all options. But I'm stuck on the selected dataIndex which having value = 'N'. There is Y or N. If some rows having value N, it must not check when I click check all. I had already make validation on it. it's work. But I want also the uncheck is appear when i click check all if it's value is 'N'. This is my code
var sm;
sm = Ext.create('Ext.selection.CheckboxModel');
gridMain = Ext.create('Ext.grid.Panel', {
id: 'gridMyapproval',
renderTo: Ext.get("sa-grid"),
store: 'myapproval-store',
selModel: sm,
height: mainContentHeight - 63, //480//mainContentHeight-138,
//title: 'Request',
columns: [{
text: 'Request Type',
width: 100,
dataIndex: 'WorkflowType'
}, {
text: 'Requestor ID',
width: 100,
dataIndex: 'RequestedByID'
}, {
text: 'Requestor Name',
width: 200,
dataIndex: 'RequestedByName'
}, {
text: 'Description',
flex: 1,
dataIndex: 'RequestDescription'
}, {
text: 'Status',
width: 150,
dataIndex: 'RequestStatusDescription'
},
{
text: 'EnableApprove',
width: 150,
dataIndex: 'EnableApprove'
},
],
dockedItems: [{
xtype: 'toolbar',
items: [actApproveAll]
}],
listeners: {
itemdblclick: function (view, record, item, index, e, eOpts) {
isGridClicked = true;
ViewDetails(FormState.VIEW);
},
afterrender: function (row, model, index) {
//$('.x-column-header-checkbox').css('display','none');
if (model.data.EnableApprove == 'N') {
grid.getSelectionModel().deselect();
}
},
selectionchange: function (row, model, index) {
if (model.data.EnableApprove == 'N') {
grid.getSelectionModel().deselect();
}
},
beforeselect: function (row, model, index) {
if (model.data.EnableApprove == 'N') {
MsgBox("Enable Approve !");
return false;
}
}
}
});
I tried to write it on afterrenderer, but it's not work.
I think you have to overrite selectAll (source) and deselectAll (source) methods of Ext.selection.CheckboxModelView.
Check this question and answer, I guess solution is somewhat you need.

Highlight grid row on edit

I am on ExtJs3.2.
There is a gridpanel with a column having a textField as an editor.
On change of value in the textfield - i need the corresponding row to be highlighted.
How do I get the 'owning' row index of the text field?
columns: [
...........
{header: 'Revenues',dataIndex: 'percentage',
editor: new Ext.form.TextField({
listeners: {
'change' : function (field, newValue, oldValue) {
if(oldValue!=newValue){
.......
//How do I get the row index?
Ext.fly(grid.getView().getRow(row)).addClass('yellow-row');
}
}
}
Is there any other way to achieve this?
Could you please try below?
var grid = Ext.grid.GridPanel({
store: yourStore,
id: 'myGrid',
colModel: new Ext.grid.ColumnModel({
defaults: {
width: 120,
sortable: true
},
columns: [
{id: 'Company', header: 'Company', width: 120, sortable: true, dataIndex: 'company'},
{header: 'Change', dataIndex: 'change'},
{
header: 'Revenue',
dataIndex: 'percentage',
editor: new Ext.form.TextField({
listeners: {
'change': function(field, newValue, oldValue) {
if (oldValue != newValue) {
var sel = Ext.getCmp('myGrid').getSelectionModel().getSelected();
// if you select more than one record use getSelections instead of getSelected
console.log(sel);
}
}
}
})
}
]
}),
sm: new Ext.grid.RowSelectionModel({singleSelect: true}),
width: 500,
height: 300,
frame: true,
title: 'My Grid'
});

How to achieve Live Search/Filtering on Multiple Fields in the Grid using Ext.Js?

I have done live search on grid. it is searching based on which column i mentioned filter code. But i need to filter grid records based on multiple column search. In below code only searches name column because mentioned only the name filed in filter code. I am not getting how to achieve multiple column value search? Can any one tell me how to achieve? great appreciated. Thank you .
Grid Code Here:
{
xtype: 'gridpanel',
flex: 2,
hidden: false,
store: store,
loadMask: true,
id: 'grid',
columns: [
{id:'id',header: 'ID', width: 100, sortable: true, dataIndex: 'id'},
{header: 'Name', width: 150, dataIndex: 'name'},
{header: 'Position', width: 150, dataIndex: 'position'},
{header: 'Ambition', width: 250, dataIndex: 'ambition'}
],
stripeRows: true,
title:'Straw Hats Crew',
},
liveSearch text change even Here:
onTextFieldChange: function(field, newValue, oldValue, options){
var grid = Ext.getCmp('grid');
if(newValue==''){
grid.store.clearFilter();
}
else {
grid.store.clearFilter();
grid.store.load().filter([
{id: 'name', property: "name", value: newValue, anyMatch: true}
]);
}
},
Something like this should work. You can specify an arbitrary filter function that can check all the fields in your model.
onTextFieldChange: function(field, newValue, oldValue, options){
var grid = Ext.getCmp('grid');
grid.store.clearFilter();
if (newValue) {
var matcher = new RegExp(Ext.String.escapeRegex(newValue), "i");
grid.store.filter({
filterFn: function(record) {
return matcher.test(record.get('id')) ||
matcher.test(record.get('name')) ||
matcher.test(record.get('position')) ||
matcher.test(record.get('ambition'));
}
});
}
}

Resources