Real simple, I've been trying to get the checkbox type to render on my list, but all I get is the value "no." Here's my settings object. Am I doing something wrong? The list renders perfectly and works properly in terms of conditional coloring, etc., just no checkboxes. HELP! and thank you.
settings = {
data: bulkListData
,dataSchema: {name: {first: null, last: null}, email: null,status: null,action: null}
,colHeaders: ['First Name', 'Last Name', 'Email','Status','Action']
,columns: [
{data: 'name.first'},
{data: 'name.last'},
{data: 'email'},
{data: 'status'},
{data: 'action'
,type: 'checkbox'
,checkedTemplate: 'yes'
,uncheckedTemplate: 'no'
}
]
,colWidths:[200,200,300,120,120]
,startRows: 5
,startCols: 5
,minRows: 5
,minCols: 5
,maxRows: 10
,maxCols: 5
,minSpareRows: 5
,autoWrapRow:true
,contextMenu: true}
I put your sample code in a fiddle and it works for me.
The only thing I needed was to fill in the bulkListData accordingly, otherwise everything is exactly like yours. Perhaps you are making the mistake exactly there - are your action properties in this array in the form of yes/no string?
I have a renderer that changes the color of a column. When this renderer is used the check boxes change to 'yes'/'no'.
When the renderer is not used the checkboxes show.
$(document).ready(function () { function getCompData() {
return [
{Comp: "Annually", year: 2006, Retirement: 'yes'},
{Comp: "Monthly", year: 2008, Retirement: 'yes'},
{Comp: "Quarterly", year: 2011, Retirement: 'no'},
{Comp: "Semi-Annually", year: 2004, Retirement: 'yes'},
{Comp: "Semi-Monthly", year: 2011, Retirement: 'no'}
];}function cellColorRenderer(instance, td, row, col, prop, value, cellProperties) {
Handsontable.TextCell.renderer.apply(this, arguments);
if (col === 1) {
td.style.textAlign = 'right';
td.style.backgroundColor = "#ccffcc";
}
}var example2 = document.getElementById('example2'); var hot2 = new Handsontable(example2,{ data: getCompData(),
startRows: 7,
startCols: 4,
colHeaders: ["Comp", "Year", "401K"],
colWidths: [120, 50, 60],
columnSorting: true,
columns: [
{
data: "Comp"
},
{
data: "year",
type: 'numeric'
},
{
data: "Retirement",
type: "checkbox",
checkedTemplate: 'yes',
uncheckedTemplate: 'no'
}
], cells:
function (row, col, prop) {
var cellProperties = {};
cellProperties.renderer = cellColorRenderer;
return cellProperties;
}, }); });
Here is the code in jsfiddle
http://jsfiddle.net/w42cp1y8/1/
Just use CheckboxRenderer instead TextRenderer:
$element.handsontable( {
cells: function( row, col, prop ) {
return {
renderer: function( instance, td, row, col, prop, value, cellProperties ) {
Handsontable.renderers.CheckboxRenderer.apply( this, arguments );
td.style.backgroundColor = value ? 'red' : 'white';
td.style.textAlign = 'center';
},
type: 'checkbox'
};
}
} );
jExcel is an alternative to handsontable. The example below is using a checkbox column type:
data = [
['Brazil', 'Classe A', 'Cheese', 1, '2017-01-12'],
['Canada', 'Classe B', 'Apples', 1, '2017-01-12'],
['USA', 'Classe A', 'Carrots', 1, '2017-01-12'],
['UK', 'Classe C', 'Oranges', 0, '2017-01-12'],
];
$('#my').jexcel({
data:data,
colHeaders: [ 'Country', 'Description', 'Type', 'Stock', 'Next purchase' ],
colWidths: [ 300, 80, 100, 60, 120 ],
columns: [
{ type: 'text' },
{ type: 'text' },
{ type: 'dropdown', source:[ {'id':'1', 'name':'Fruits'}, {'id':'2', 'name':'Legumes'}, {'id':'3', 'name':'General Food'} ] },
{ type: 'checkbox' },
{ type: 'calendar' },
]
});
<link href="https://cdnjs.cloudflare.com/ajax/libs/jexcel/1.2.2/css/jquery.jexcel.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jexcel/1.2.2/js/jquery.jexcel.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jexcel/1.2.2/js/jquery.jcalendar.min.js"></script>
<div id="my"></div>
Related
This is the code I used from material UI site. Every time I edit something, pressing ENTER or TAB will result in the following warning and won't proceed to next cell. Any ideas? TIA!
index.js:1 Warning: This synthetic event is reused for performance
reasons. If you're seeing this, you're accessing the method key on a
released/nullified synthetic event. This is a no-op function. If you
must keep the original synthetic event around, use event.persist().
import * as React from 'react';
import { DataGrid } from '#mui/x-data-grid';
function getFullName(params) {
return `${params.row.firstName || ''} ${params.row.lastName || ''}`;
}
function setFullName(params) {
const [firstName, lastName] = params.value.toString().split(' ');
return { ...params.row, firstName, lastName };
}
export default function ValueGetterSetterGrid() {
return (
<div style={{ height: 400, width: '100%' }}>
<DataGrid rows={defaultRows} columns={columns} />
</div>
);
}
const columns = [
{ field: 'firstName', headerName: 'First name', width: 130, editable: true },
{ field: 'lastName', headerName: 'Last name', width: 130, editable: true },
{
field: 'fullName',
headerName: 'Full name',
width: 160,
editable: true,
valueGetter: getFullName,
valueSetter: setFullName,
sortComparator: (v1, v2) => v1.toString().localeCompare(v2.toString()),
},
];
const defaultRows = [
{ id: 1, lastName: 'Snow', firstName: 'Jon' },
{ id: 2, lastName: 'Lannister', firstName: 'Cersei' },
{ id: 3, lastName: 'Lannister', firstName: 'Jaime' },
{ id: 4, lastName: 'Stark', firstName: 'Arya' },
{ id: 5, lastName: 'Targaryen', firstName: 'Daenerys' },
];
I am looking for a way to display the numeric value 0 in a dropdown list that also includes placeholder text when the cell is empty. Currently, if 0 is selected the placeholder text shows through. I'm hoping for a built-in option and I'd like to avoid casting the number to string and back if I can (that would tear up my current validation scheme). The following example is modified from the HandsOnTable dropdown docs. The 'Chassis Color' column contains the issue.
jsfiddle:
https://jsfiddle.net/y3pL0vjq/
snippet:
function getCarData() {
return [
["Tesla", 2017, "black", "black"],
["Nissan", 2018, "blue", "blue"],
["Chrysler", 2019, "yellow", "black"],
["Volvo", 2020, "white", "gray"]
];
}
var
container = document.getElementById('example1'),
hot;
hot = new Handsontable(container, {
data: getCarData(),
colHeaders: ['Car', 'Year', 'Chassis color', 'Bumper color'],
columns: [
{},
{type: 'numeric'},
{
type: 'dropdown',
placeholder: "blah",
source: [null, 0, 1, 2, 3]
},
{
type: 'dropdown',
source: ['yellow', 'red', 'orange', 'green', 'blue', 'gray', 'black', 'white']
}
]
});
The best way I found to handle this dropdown list of numbers is to omit the "type" attribute and specify the editor and validator as 'autocomplete. Then make a custom renderer to merge the NumericRenderer functionality with the autocomplete dropdown list.
To finalize the similar look and feel of the native dropdown function, you then add "strict: true" and "filter: false", as explained in the dropdown docs.
Internally, cell {type: "dropdown"} is equivalent to cell {type: "autocomplete", strict: true, filter: false}.
Dropdown Docs
Example:
function getCarData() {
return [
["Tesla", 2017, null, "black"],
["Nissan", 2018, 0, "blue"],
["Chrysler", 2019, 1, "black"],
["Volvo", 2020, 2, "gray"]
];
}
var
container = document.getElementById('example1'),
hot;
function myRenderer(instance, td, row, col, prop, value, cellProperties) {
Handsontable.renderers.NumericRenderer.apply(this, arguments);
td.innerHTML += '<div class="htAutocompleteArrow">▼</div>'
}
hot = new Handsontable(container, {
data: getCarData(),
colHeaders: ['Car', 'Year', 'Chassis color', 'Bumper color'],
columns: [
{},
{type: 'numeric'},
{
editor: 'autocomplete',
validator: 'autocomplete',
renderer: myRenderer,
strict: true,
filter: false,
placeholder: "blah",
source: [null, 0, 1, 2, 3]
},
{
type: 'dropdown',
source: ['yellow', 'red', 'orange', 'green', 'blue', 'gray', 'black', 'white']
}
]
});
I am having table in which date column is in extreme right position.
When i click on it i can't see whole calendar.
hot = new Handsontable(container, {
data: getCarData(),
colHeaders: ['Car', 'Model', 'Registration test', 'Price', 'Registration date'],
columns: [
{
type: 'autocomplete',
source: ['Audi', 'BMW', 'Chrysler', 'Citroen', 'Mercedes', 'Nissan', 'Opel', 'Suzuki', 'Toyota', 'Volvo'],
strict: false
},
{
// 2nd cell is simple text, no special options here
},
{
type: 'text'
},
{
type: 'numeric',
format: '$ 0,0.00'
},
{
type: 'date',
dateFormat: 'MM/DD/YYYY',
correctFormat: true,
defaultDate: '01/01/1900'
}
]
});
Please check the js fiddle.
http://jsfiddle.net/hemantmalpote/Lc8r4n6z/
I need to display a checkbox for column "Active" and when I change the selection to be to able to make an ajax request, to update the database.
Some sample code will help me a lot.
Thanks.
Please check this link: Extjs Grid plugins.
You can check sources for second grid.
Also you need listen 'selectionchange' event for selection model of the grid - so you'll have selected rows and then you can submit a request to server or whatever you need.
If you need specific column (not the first one) - you can check this link: Checkbox in the grid
And I think this is same here too: how to add checkbox column to Extjs Grid
This is example from one of my projects:
Ext.define('Magellano.view.news.List' ,{
extend: 'Ext.grid.Panel',
alias : 'widget.newslist',
store: 'News',
remoteSort: false,
dockedItems: [{
xtype: 'toolbar',
items: [{
text: 'Online',
id: 'online-button',
enableToggle: true,
icon: '/images/light-bulb.png',
pressed: true,
handler: onItemToggle
}, { text: 'Preview',
id: 'preview-button',
enableToggle: true,
pressed: true
}],
initComponent: function() {
this.selModel = Ext.create('Ext.selection.CheckboxModel', {
singleSelect: false,
sortable: false,
checkOnly: true
});
this.columns = [
{ text: '', width: 28, renderer: function(val) { return "<img src='/images/star-empty.png' height='16' width='16'></img>"}},
{ text: 'Date', width: 60, dataIndex: 'newstime', renderer: renderDate},
{ text: 'Agency', width: 60, dataIndex: 'agency', renderer: function(val) { return val;}},
{ text: 'Category', width: 60, dataIndex: 'category', renderer: function(val) { return val;}},
{ text: 'Title', flex: 1, dataIndex: 'title',
renderer: function(val) { return Ext.String.format('<b>{0}</b>', val); }
}
];
this.title = "News from " + Ext.Date.dateFormat(new Date(), "j M Y");
this.callParent(arguments);
}
}
The important part is that in the initComponent you create the selection model:
this.selModel = Ext.create('Ext.selection.CheckboxModel', {
singleSelect: false,
sortable: false,
checkOnly: true
});
I'm using ExtJS 3.3.0 with a datagrid that consumes a JSON data store (Ext.data.GroupingStore).
When I'm not grouping by a column, I can sort just fine, however when grouping by a column, the sort algorithm seems to fall apart.
I have another data grid that does server side sorting (and grouping and paging) and this works just fine. Comparing the the code between the two has left me stumped for the difference that's making one work and the other not work.
Many thanks in advance.
CW.App.FileGrid = {
store : null,
initComponent: function(){
this.store = new Ext.data.GroupingStore({
autoLoad:true,
url:'/sites/files.js',
groupField:'modified',
// Sort by whatever field was just grouped by. This makes the data
// make more sense to the user.
groupOnSort:true,
remoteSort:false,
remoteGroup:false,
sortInfo:{
field:'modified',
direction:'DESC'
},
reader: new Ext.data.JsonReader({
idProperty:'filename',
root:'data',
fields: [
'iconCls',
{
name: 'modified',
type: 'date',
dateFormat:'timestamp'
},
'description', 'folder', 'filename',
'filesize', 'ext', 'dateGroup']
})
});
// this.store.setDefaultSort('modified', 'DESC');
Ext.apply(this, {
store: this.store,
loadMask:true,
columns: [
{
xtype:'actioncolumn',
items:[{
getClass:function(v,meta,rec){
return rec.get('iconCls');
}
}],
width:25
},{
id:'filename',
header: "Filename",
sortable: true,
dataIndex: 'filename'
},{
id:'ibmu',
header: "iBMU",
width:50,
sortable:true,
dataIndex: 'folder'
},{
id:'date',
header: "Date",
width: 65,
sortable: true,
dataIndex: 'modified',
renderer: Ext.util.Format.dateRenderer('Y-m-d h:i'),
groupRenderer:function(v,unused,r,rowIdx,colIdx,ds){
return r.data['dateGroup'];
}
},{
id:'type',
header: "Type",
width: 70,
sortable: true,
dataIndex: 'description'
},{
id:'size',
header: "Size",
width: 50,
sortable: true,
dataIndex: 'filesize',
renderer: Ext.util.Format.fileSize
},{
xtype:'actioncolumn',
items:[{
icon: '/img/fam/drive_disk.png',
tooltip: 'Download file',
handler: function(grid, rowIndex, colIndex){
var rec = store.getAt(rowIndex);
location.href = Ext.urlAppend('/ibmus/download/', Ext.urlEncode({
folder: rec.get('folder'),
filename: rec.get('filename')
}));
}
}]
}
],
autoExpandColumn:'filename',
view: new Ext.grid.GroupingView({
emptyText: 'No files found. Please wait up to 24 hours after activating your account for files to appear.',
forceFit:true,
groupTextTpl: '{text} ({[values.rs.length]} {[values.rs.length > 1 ? "Files" : "File"]})'
}),
frame:false,
width: '100%',
height: 250,
collapsible: false,
animCollapse: false
});
CW.App.AlarmGrid.superclass.initComponent.call(this);
}
};