actioncolumn xtype column header is showing Actions in column hide/show list - extjs4.2

In EXT JS grid, for column with xtype: actioncolumn, the column header is not showing up in show/hide column list. It comes up as 'Actions' by default for actioncolumn column.
Can we override actual column header in the list of columns to show/hide for actioncolumn columns? Image shows a screenshow of examples from sencha examples.

If you want change the Label in Columns, You need to use a config called menuText for actioncolumn
Example: (https://fiddle.sencha.com/#fiddle/1944)
{
xtype:'actioncolumn',
width:50,
menuText: 'My Actions',
items: [{
icon: 'extjs-build/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-build/examples/restful/images/delete.png',
tooltip: 'Delete',
handler: function(grid, rowIndex, colIndex) {
var rec = grid.getStore().getAt(rowIndex);
alert("Terminate " + rec.get('firstname'));
}
}]
}

Related

Export custom column in Ag Grid to excel

I have a custom column in Ag Grid which has an image and text in it.
When I export the whole table to excel I get [object] as value for the custom column.
Is there a way to export only the text from the custom column?
Project is in Angular typescript
Good day, please have a look at the docs of customising-cell-and-row-group-values
Description:
You can create custom options and describe what exact field should be passed in export with concrete value:
First look for how can create custom options
Looking for exportDataAsExcel method and ExcelExportParams
Example:
const getContextMenuItems = ({ api, ...restProps }) => {
return [
// other options
{
name: 'Export',
tooltip: 'Export',
subMenu: [
{
name: 'Excel Export',
action: () => api.exportDataAsExcel({
// other params like columnKeys e.t.c
processCellCallback: ({ column, value }) => {
// Rules for your custom cellRenderer here:
if (column.colId === 'yourCustomFieldId') {
return value.customText;
}
return value;
},
}),
},
],
},
];
};

How to select column data in ag-grid

I have to enable columns selection and perform operation like export Excel/copy to clipboard on particular columns selected.
The requirement is when I click on column header it should select the entire column.
How can this be achieved?
There are a few ways to do it.
One would be to add a new 'Select Column' entry to the Column Menu and then in the Action create a new cell range. Something like this should do the trick:
var gridOptions = {
....
getMainMenuItems: getMainMenuItems,
....
}
function getMainMenuItems(params) {
var menuItems = params.defaultItems.slice(0);
menuItems.push({
name: 'Select Column',
action: function () {
gridOptions.api!.clearRangeSelection();
const cellRangeParams: CellRangeParams = {
rowStartIndex: 0,
rowEndIndex: gridOptions.api!.getDisplayedRowCount(),
columnStart: params.column.getId(),
columnEnd: params.column.getId(),
};
gridOptions.api!.addCellRange(cellRangeParams);
},
});
return menuItems;
}

How to add Row Header in Ag-grid?

Please refer to the image shown below. (The highlighted part is the ROW header that I need in AG-Grid)
I am not sure about the functional use case of this first column for you.
Nevertheless you can achieve this by adding it to column definition as shown below.
var gridOptions = {
// define grid columns
columnDefs: [
// using default ColDef
{
headerName: ' ',
field: '__',
width: 15,
sortable: false,
cellStyle: {
// you can use either came case or dashes, the grid converts to whats needed
backgroundColor: 'lightgrey', // whatever cell color you want
},
},
...
}
Created working sample plnkr here.
As far as I know ag-grid doesn't have any built-in support for row headers, but as a workaround you can make your first column appear as row headers. I recommend making the whole column look a little different compared to the other columns (including the column header if it's not blank) so it can clearly be seen they are column headers, not standard row data.
Example column definitions:
ColumnDefs: [
{ headerName: 'Column Title 1', field: 'Column1', minWidth: 100, headerClass: "upperLeftCell", cellStyle: {
backgroundColor: 'AliceBlue', //make light blue
fontWeight: 'bold' //and bold
}
},
{ headerName: 'Column Title 2', field: 'Column2', minWidth: 100 },
{ headerName: 'Column Title 3', field: 'Column3', minWidth: 100 }
]
You can also style in SCSS as shown here with the upper left cell:
::ng-deep .ag-header-cell.upperLeftCell {
background-color: aliceblue;
font-weight: bold;
}
In your data rows: you have to enter in the first column the title you want for each row.
Add this as your first colDef. It will render a index column that is unmovable. I have a separate IndexColumnCellRender so won't look exact the same, fill in cellStyle to fit your needs, or make a dedicated cell render like me.
const rowIndexColumn: ColDef = {
valueGetter: ({ node }) => {
const rowIndex = node?.rowIndex;
return rowIndex == null ? "" : rowIndex + 1;
},
width: columnWidth,
headerName: "",
colId: "some-id",
field: "some-id",
suppressNavigable: true,
suppressPaste: true,
suppressMovable: true,
suppressAutoSize: true,
suppressMenu: true,
lockPosition: true,
cellStyle: { padding: 0 },
};

TinyMCE: inserting simple snippets of text via dropdown?

In TinyMCE 4, I'm looking to create a dropdown menu (whether as a toolbar button or in a menu) containing a list of values that should be inserted at cursor position simply by selecting them in the dropdown.
I've tried playing with the template plug-in, which kind of works, but it's too heavy and complex to use for what I need (it doesn't create a dropdown, instead it opens a popup which lets you preview your template, and I really don't need all that).
Is there a simpler way to do that? I don't need text replacement, class or date insertion, preview in a popup, or any of that advanced stuff. Just insert a static text value at cursor position.
Here is a TinyMCE Fiddle that shows hw to do what you want:
http://fiddle.tinymce.com/orgaab/1
The key code is this:
setup: function (editor) {
editor.addButton('custombutton', {
type: 'listbox',
text: 'Custom Listbox',
icon: false,
onselect: function (e) {
editor.insertContent(this.value());
},
values: [
{ text: 'Bold Text', value: ' <strong>Some bold text!</strong>' },
{ text: 'Italic Text', value: ' <em>Some italic text!</em>' },
{ text: 'Regular Text', value: ' Some plain text ...' }
]
});
}
If you want to add stuff to a Menu instead (based on your follow up comment) you can do this:
http://fiddle.tinymce.com/orgaab/4
The key code in this update is:
editor.addMenuItem('custommenuoptions', {
separator: 'before',
text: 'Custom Menu Options',
context: 'insert',
prependToContext: true,
menu: [
{ text: 'Bold Text', onclick: function() {editor.insertContent(' <strong>Some bold text!</strong>')} },
{ text: 'Italic Text', onclick: function() {editor.insertContent(' <em>Some italic text!</em>')} },
{ text: 'Regular Text', disabled: true, onclick: function() {editor.insertContent(' Some plain text ...')} }
]
});

Extjs grid with multiselect feature to retrieve value of selected lists

Let's say I have a grid with multiselect option on, when user selects 4 lists and wants to get the values ( alerted on screen) how would I do that? And how would I disable buttons untill at least one list is selected?
All questions you've asked are answered many times already. Also there are good ExtJS examples on sencha.com. For example list view grid shows multiple select and editable grid with writable store shows button enable on click. But THE MOST important is documentation! Let me explain functionality on following code. Most of it is from list view example.
This grid gets JSON from list.php which has following structure
{"authors":[{"surname":"Autho1"},{"surname":"Autho2"}]}
And the grid:
Ext.require([
'Ext.grid.*',
'Ext.data.*',
'Ext.panel.*'
]);
Ext.onReady(function(){
// Here i've definned simple model with just one field
Ext.define('ImageModel', {
extend: 'Ext.data.Model',
fields: ['surname']
});
var store = Ext.create('Ext.data.JsonStore', {
model: 'ImageModel',
proxy: {
type: 'ajax',
url: 'list.php',
reader: {
type: 'json',
root: 'authors'
}
}
});
store.load();
var listView = Ext.create('Ext.grid.Panel', {
id: 'myPanel', // Notice unique ID of panel
width:425,
height:250,
collapsible:true,
renderTo: Ext.getBody(),
store: store,
multiSelect: true,
viewConfig: {
emptyText: 'No authors to display'
},
columns: [{
text: 'File',
flex: 50,
// dataIndex means which field from model to load in column
dataIndex: 'surname'
}],
dockedItems: [{
xtype: 'toolbar',
items: [{
// This button will log to console authors surname who are selected
// (show via firebug or in chrome js console for example)
text: 'Show selected',
handler: function() {
// Notice that i'm using getCmp(unique Id of my panel)
// to get panel regerence. I could also use
// this.up('toolbar').up('myPanel')
// see documentation for up() meaning
var selection = Ext.getCmp('myPanel').getSelectionModel().getSelection();
for (var i=0; i < selection.length; i++) {
console.log(selection[i].data.surname);
}
}
},{
text: 'Disabled btn',
id: 'myHiddenBtn', // Notice unique ID of my button
disabled: true // disabled by default
}]
}]
});
// Here i'm waiting for event which is fired
// by grid panel automatically when you click on
// any item of grid panel. Then I lookup
// my button via unique ID and set 'disabled' property to false
listView.on('itemclick', function(view, nodes){
Ext.getCmp('myHiddenBtn').setDisabled(false);
});
});
I didn't knew how to do this from top of my head, but I used documentation and the result works ;-). See Grid panel docs for more information.