How to add event on click on ant design vue table column title? - vue.js

const columns = [
{ title: 'Name', dataIndex: 'name', width: 300
onHeaderCell: column => {
return {
onClick: e => {
this.customize(e);
},
};
},},
{ title: 'Employee ID', dataIndex: 'displayId', width: 150 },
{ title: 'Normal', dataIndex: 'normal.name', width: 100 },
{ title: 'Overtime', dataIndex: 'overtime.name', width: 100 },
{ title: 'Holiday', dataIndex: 'holiday.name', width: 100 },
{ title: 'Rest Day', dataIndex: 'restDay.name', width: 100 },
];
I have an ant design vue table and want to add event on click to change the title name. But I can't add on click event and customize the column title.
Is there any way to make this happen when click the column title will triggered a function?

I assume you are using this Ant Design Vue and this Table component.
You can use custom title by specify column.slots.title:
const columns = [
{
dataIndex: 'name',
key: 'name',
slots: {
title: 'customTitle'
}
}
]
And define your customTitle slot:
<span slot='customTitle'>
<div #click='editTitle'>{{ title }}</div>
</span>
Example

You can add a parameter for each item for example "isClickable" and put a click listener on each item of the v-for which will enter in a method that check if the item is clickable or not.
<template>
<div>
<div
v-for="column in columns"
#click="clickOnColumn(column)"
/>
</div>
</template>
<script>
export default {
data: () => ({
columns: [
{
title: 'Name',
dataIndex: 'name',
width: 300,
isClickable: true,
},
{ title: 'Employee ID', dataIndex: 'displayId', width: 150 },
{ title: 'Normal', dataIndex: 'normal.name', width: 100 },
{ title: 'Overtime', dataIndex: 'overtime.name', width: 100 },
{ title: 'Holiday', dataIndex: 'holiday.name', width: 100 },
{ title: 'Rest Day', dataIndex: 'restDay.name', width: 100 },
],
}),
methods: {
clickOnColumn(column) {
if (column.isClickable) {
// Execute code
} else {
return null
}
},
},
}
</script>
<style lang="scss" scoped>
</style>

Related

Panel with borderLayout fill it's parent body

I want to add panel to one of tabs of tabPanel, I use border layout for panel but when i add panel to tab it can't fill it's parent body.
panel code:
var viewport = Ext.create('Ext.panel.Panel', {
layout: {
type: 'border',
padding: 5
},
defaults: {
split: true,
anchor:'100%'
},
id:'viewPort',
width:600,
height:600,
items: [{
region: 'west',
collapsible: true,
title: 'Starts at width 30%',
split: true,
width: '17%',
minWidth: 100,
minHeight: 140,
layout:{
type:'vbox',
align:'stretch'
},
items: [show,treePanel,propGrid]
},tabs]
});
tab code that is parent of panel and when user click on it panel loaded to it dynamically:
var mainTabs = Ext.create('Ext.tab.Panel', {
layout: 'anchor',
id:'mtabs',
defaults: {
split: true,
anchor: '100%'
},
items: [{
title: 'Layout Window',
closeAction: 'hide',
layout: {
type: 'border',
padding: 5
},
//anchor: '100%',
width:600,
height:600,
listeners: {
activate:function (tab) {
}
},
items: [{
region: 'west',
collapsible: true,
title: 'Starts at width 30%',
split: true,
width: '17%',
minWidth: 100,
minHeight: 140,
layout:'vbox',
items: [historyTreePanel,propGrid]
},tabs]
},{
title: 'History',
//xtype:'panel',
width:2000,
height:1024,
html: 'Please Wait...',
id:'history-tab',
layout:'fit',
layout: 'hbox',
default: {
anchor:'100%'
},
//iconCls: 'favorites',
//cls: 'card1',
listeners: {
activate:function (tab) {
if(!flag){
flag = true;
$.getScript("/FleetManagement/js/history/fleethistory.js", function(data, textStatus, jqxhr) {
Ext.getCmp('history-tab').add(viewport);
});
}
}
}
}],
renderTo : Ext.getBody()
});
});
in the above code tab with id:'history-tab' is my mentioned tab.How can i fix this problem?
It seems your code missing some of the components. Your tab should have correct layout. Sample code. jsfiddle example here . Hope this helps
Ext.onReady(function() { var resultsPanel = Ext.create('Ext.Panel',{
frame:false,
border:false,
collapsible:false,
title:'tab main',
layout:'border',
items:[{
region: 'center',
id:'centerPanel',
title:'center',
xtype:'panel',
layout:'fit',
border: true,
items:[{id:'grid',xtype:'panel'}]
},
{
region: 'west',
id:'westPanel',
title:'facets',
xtype:'panel',
width:'15%',
collapseMode: 'mini',
collapsible:true,
autoScroll: true,
border: false,
baseCls:'x-plain',
split: true ,
items:[{id:'facet',xtype:'panel'}]
}
]
}); var subtab = { xtype:'tabpanel',
title:'moretabs',
activeTab: 0,//tabActive,
closable:true,
border:false,
id:'idd',
items: [{border:false,layout: 'fit',cls: 'inner-tab-custom', autoShow:true, id:'sub1-',title: 'nested1',items:[resultsPanel]}] };
var tabPanel = Ext.create('Ext.tab.Panel', {
layout:'fit',
height:200,
msgDisplay: 'block',
//deferredRender:false,
border:false,
items: [subtab]
}).render(Ext.getBody());
});

Sencha Ext JS4.. [Grid ActionColumn] doesn't display

I'm new with sencha js 4. I already followed the instruction from the sencha documentation guide regarding with how to use actioncolumn, but it doesn't display on my grid.
"Where did I miss?. is there anything that I skipped? or is there anything that I didn't included? help.."
I use the kitchenSink sample that sencha provided me. I tried to manipulate it and added an actioncolumn from one of the grids in the kitchenSink sample
Here is my code:
Ext.define('PayrollLite.view.GridExample', {
extend: 'Ext.grid.Panel',
frame: true,
width: 1200,
height: 750,
store: 'Employees',
columns:
[
{ text: 'Employee Code', width: '10%', dataIndex: 'EmployeeCode' },
{ text: 'Last Name', width: '22%', dataIndex: 'LastName'},
{ text: 'First Name', width: '25%', dataIndex: 'FirstName' },
{ text: 'Middle Name', width: '15%', dataIndex: 'MiddleName' },
{ text: 'Position', width: '15%', dataIndex: 'PositionID', sortable: false },
{
xtype:'actioncolumn',
width:50,
items: [{
icon: 'extjs/examples/shared/icons/fam/cog_edit.png', // Use a URL in the icon config
tooltip: 'Edit',
handler: function(grid, rowIndex, colIndex) {
var rec = grid.getStore().getAt(rowIndex);
alert("Edit " + rec.get('firstname'));
}
},{
icon: 'extjs/examples/restful/images/delete.png',
tooltip: 'Delete',
handler: function(grid, rowIndex, colIndex) {
var rec = grid.getStore().getAt(rowIndex);
alert("Terminate " + rec.get('firstname'));
}
}]
}
]
});
My best guess would be the widths - try setting the other columns to flex widths instead. Like so:
Ext.define('PayrollLite.view.GridExample', {
extend: 'Ext.grid.Panel',
frame: true,
width: 1200,
height: 750,
store: 'Employees',
columns:
[
{ text: 'Employee Code', flex: '1', dataIndex: 'EmployeeCode' },
{ text: 'Last Name', flex: '2.2', dataIndex: 'LastName'},
{ text: 'First Name', flex: '2.5', dataIndex: 'FirstName' },
{ text: 'Middle Name', flex: '1.5', dataIndex: 'MiddleName' },
{ text: 'Position', flex: '1.5', dataIndex: 'PositionID', sortable: false },
{
xtype:'actioncolumn',
width:50,
items: [{
icon: 'extjs/examples/shared/icons/fam/cog_edit.png', // Use a URL in the icon config
tooltip: 'Edit',
handler: function(grid, rowIndex, colIndex) {
var rec = grid.getStore().getAt(rowIndex);
alert("Edit " + rec.get('firstname'));
}
},{
icon: 'extjs/examples/restful/images/delete.png',
tooltip: 'Delete',
handler: function(grid, rowIndex, colIndex) {
var rec = grid.getStore().getAt(rowIndex);
alert("Terminate " + rec.get('firstname'));
}
}]
}
]
});

Remove a record from a Grid Locally

I have a Grid in a Window. When i click on a row of that window and click on the remove button, that row should get removed from the window. (I think i will have to remove it from Store and reload the grid, so the changes will be picked)
I am unable to get the click event and remove the row from the store. I have added the button for this but not able to get the Grid record and remove it from store and reloading it.
My code is as follows;
Ext.define('MyApp.view.Boy', {
extend: 'Ext.window.Window',
alias: 'widget.boy',
height: 800,
width: 900,
layout: {
type: 'absolute'
},
initComponent: function() {
var me = this;
Ext.applyIf(me, {
items: [
{
xtype: 'gridpanel',
height: 500,
width: 800,
title: 'My Grid Panel',
store: 'School',
viewConfig: {
},
columns: [
{
xtype: 'gridcolumn',
dataIndex: 'Id',
text: 'id'
},
{
xtype: 'gridcolumn',
dataIndex: 'name',
text: 'name'
}
]
},
{
xtype: 'button',
height: 40,
width: 150,
text: 'Remove',
listeners: {
click: {
fn: me.removebuttonclick,
scope: me
}
}
}
]
});
me.callParent(arguments);
},
removebuttonclick: function(button, e, options) {
console.log('removebuttonclick');
}
});
Something like:
Ext.define('MyApp.view.Boy', {
extend: 'Ext.window.Window',
alias: 'widget.boy',
height: 800,
width: 900,
layout: {
type: 'absolute'
},
initComponent: function() {
var me = this;
var this.grid = Ext.widget({
xtype: 'gridpanel',
height: 500,
width: 800,
title: 'My Grid Panel',
store: 'School',
viewConfig: {
},
columns: [
{
xtype: 'gridcolumn',
dataIndex: 'Id',
text: 'id'
},
{
xtype: 'gridcolumn',
dataIndex: 'name',
text: 'name'
}
]
});
Ext.applyIf(me, {
items: [
this.grid, //oopsie
{
xtype: 'button',
height: 40,
width: 150,
text: 'Remove',
listeners: {
click: {
fn: me.removebuttonclick,
scope: me
}
}
}
]
});
me.callParent(arguments);
},
removebuttonclick: function(button, e, options) {
var me = this;
Ext.Array.each(this.grid.getSelectionModel().selected,function(record, index,selectedRows){
me.grid.getStore().remove(record);
});
}
});

Change border of grid

I have following code that I creating a grid
var store = Ext.create('Ext.data.ArrayStore', {
fields: [
{ name: 'company' },
{ name: 'price', type: 'float' },
{ name: 'change', type: 'float' },
{ name: 'pctChange', type: 'float' }
],
data: myData
});
var grid = Ext.create('Ext.grid.Panel', {
store: store,
renderTo: 'divGrid',
columns: [
{ text: 'Company',
flex: 1,
dataIndex: 'company'
},
{ text: 'Price',
flex: 1,
dataIndex: 'price'
},
{ text: 'Change',
flex: 1,
dataIndex: 'change'
},
{ text: '% Change',
flex: 1,
dataIndex: 'pctChange'
}],
height: 250,
width: '100%',
title: 'Array Grid',
renderTo: 'grid-example',
viewConfig: {
stripeRows: true
}
});
});
I want to change color and width of border grid. How can I do it ?
Quick and dirty you can set this config on any grid or really any component that draws a box:
style: 'border: solid Red 2px'
The more correct way is to create a css rule and set cls:'myRedBorderRule' in the config.
EDIT:
var grid = Ext.create('Ext.grid.Panel', {
store: store,
renderTo: 'divGrid',
style: 'border: solid Red 2px',
.....
ExtJS Grid Panel class provides you with parameters to define your custom styles. You can make use of the following class parameters :
border
bodyStyle
bodyCls
bodyBorder
bodyPadding
You can use combination of these parameters to manipulate the grid's border and body styles. Refer to the docs for details of these parameters.
Add below css to remove border
.x-panel-body .x-grid-item-container .x-grid-item {
border: none;
}

Using ExtJS4, any easy way to deal with a checkbox in a grid panel?

I've written a bulky renderer that feels like it could be simpler. I'm wanting two way binding to a checkbox (from the store). below is what I've done which just feels wrong, but I can't find another way to do it.
columns: [
{ header: 'PresidentNumber', dataIndex: 'PresidentNumber', flex: 1 },
{ header: 'FirstName', dataIndex: 'FirstName', sortable: true, flex: 1 },
{ header: 'LastName', dataIndex: 'LastName', sortable: true, flex: 1 }, {
header: 'TookOffice',
dataIndex: 'TookOffice',
renderer: Ext.util.Format.dateRenderer('m/d/Y')
}, {
header: 'LeftOffice',
dataIndex: 'LeftOffice',
renderer: Ext.util.Format.dateRenderer('m/d/Y'),
flex: 1
}, {
header: 'Impeached',
dataIndex: 'Impeached',
flex: 1,
renderer: function (value, cell) {
if (value) {
return '<input type="checkbox" name="mycheckbox" checked="checked" />';
}
else {
return '<input type="checkbox" name="mycheckbox" />';
}
}
},
{ header: 'Income', dataIndex: 'Income', flex: 1, renderer: Ext.util.Format.usMoney }
]
There is a user extension called CheckColumn (located in examples/ux/CheckColumn.js) with an xtype of "checkcolumn".
{
xtype: 'checkcolumn',
header: 'Impeached',
dataIndex: 'Impeached',
flex: 1
}