When I add a toggle column to a grid with a search it does not appear to function. I have modified the Grid with Search Demo to include a toggle. But when I try to search on it the drop down just gives me an "Is" option and I cannot enter anything for the search clause.
searches: [
{ field: 'recid', caption: 'ID ', type: 'int' },
{ field: 'lname', caption: 'Last Name', type: 'text' },
{ field: 'fname', caption: 'First Name', type: 'text' },
{ field: 'email', caption: 'Email', type: 'list', options: { items: ['[email protected]', '[email protected]', '[email protected]']} },
{ field: 'auth', caption: 'Auth', type: 'toggle' }
],
columns: [
{ field: 'recid', caption: 'ID', size: '50px', sortable: true, attr: 'align=center' },
{ field: 'lname', caption: 'Last Name', size: '30%', sortable: true },
{ field: 'fname', caption: 'First Name', size: '31%', sortable: true },
{ field: 'email', caption: 'Email', size: '40%' },
{ field: 'auth', caption: 'Auth', render: 'toggle', size: '20px' }
]
jsFiddle: https://jsfiddle.net/c9r6pk7m/4/
While toggle
is a valid render value, it's not a valid searches type.
See: http://w2ui.com/web/docs/1.5/w2grid.searches
You could use list
instead, though I must admit, I had to "cheat" with the false
value, by mapping it to {id:"0", text: "No"}
.
$(function () {
$('#grid').w2grid({
name: 'grid',
show: {
toolbar: true,
footer: true
},
multiSearch: true,
searches: [
{ field: 'recid', caption: 'ID ', type: 'int' },
{ field: 'lname', caption: 'Last Name', type: 'text' },
{ field: 'fname', caption: 'First Name', type: 'text' },
{ field: 'email', caption: 'Email', type: 'list', options: { items: ['[email protected]', '[email protected]', '[email protected]']} },
{ field: 'auth', caption: 'Auth', type: 'list', options: { items: [{id:true, text: "Yes"}, {id:"0", text: "No"}]} }
],
columns: [
{ field: 'recid', caption: 'ID', size: '50px', sortable: true, attr: 'align=center' },
{ field: 'lname', caption: 'Last Name', size: '30%', sortable: true },
{ field: 'fname', caption: 'First Name', size: '31%', sortable: true },
{ field: 'email', caption: 'Email', size: '40%' },
{ field: 'auth', caption: 'Auth', render: 'toggle', size: '20px' }
],
records: [
{ recid: 1, fname: 'Jane', lname: 'Doe', email: '[email protected]', auth: true },
{ recid: 2, fname: 'Stuart', lname: 'Motzart', email: '[email protected]', auth: true },
{ recid: 3, fname: 'Jin', lname: 'Franson', email: '[email protected]', auth: true },
{ recid: 4, fname: 'Susan', lname: 'Ottie', email: '[email protected]', auth: true },
{ recid: 5, fname: 'Kelly', lname: 'Silver', email: '[email protected]', auth: true },
{ recid: 6, fname: 'Francis', lname: 'Gatos', email: '[email protected]', auth: true },
{ recid: 7, fname: 'Mark', lname: 'Welldo', email: '[email protected]', auth: false },
{ recid: 8, fname: 'Thomas', lname: 'Bahh', email: '[email protected]', auth: false },
{ recid: 9, fname: 'Sergei', lname: 'Rachmaninov', email: '[email protected]', auth: false },
{ recid: 20, fname: 'Jill', lname: 'Doe', email: '[email protected]', auth: false },
{ recid: 21, fname: 'Frank', lname: 'Motzart', email: '[email protected]', auth: false },
{ recid: 22, fname: 'Peter', lname: 'Franson', email: '[email protected]', auth: false },
{ recid: 23, fname: 'Andrew', lname: 'Ottie', email: '[email protected]', auth: false },
{ recid: 24, fname: 'Manny', lname: 'Silver', email: '[email protected]', auth: false },
{ recid: 25, fname: 'Ben', lname: 'Gatos', email: '[email protected]', auth: true },
{ recid: 26, fname: 'Doer', lname: 'Welldo', email: '[email protected]', auth: true },
{ recid: 27, fname: 'Shashi', lname: 'Bahh', email: '[email protected]', auth: true },
{ recid: 28, fname: 'Av', lname: 'Rachmaninov', email: '[email protected]', auth: true }
]
});
});