How to add buttons into datatables in flutter? - windows
I am using this package for flutter datables but the problem with this pakage is i am not able to add widget in this datatables row...
Is anyone has any idea how can I do that ? I tried other packages but this is really nice. but this has that problem...
I want to add edit,print,view button in the row but Not able to add...
code
List<Map<String, dynamic>> data = [
{
"_id": 1,
"invoice_no": "101101",
"counter": "Satara",
"customer": "Swapnil Mane",
"customer_type": "Mart",
"date": "20-10-2022",
"qty": "10002",
"grand_total": 2000,
"status": "Done"
},
];
WebDataTable(
initialFirstRowIndex: 0,
rowsPerPage: 12,
source: WebDataTableSource(
sortAscending: true,
columns: [
WebDataColumn(
sortable: true,
name: '_id',
label: const Text('Sr. No'),
dataCell: (value) => DataCell(Text('$value')),
),
WebDataColumn(
name: 'invoice_no',
label: const Text('Invoice No'),
dataCell: (value) => DataCell(Text('$value')),
),
WebDataColumn(
name: 'counter',
label: const Text('Counter Name'),
dataCell: (value) => DataCell(Text('$value')),
),
WebDataColumn(
name: 'customer',
label: const Text('Customer Name'),
dataCell: (value) => DataCell(Text('$value')),
),
WebDataColumn(
name: 'customer_type',
label: const Text('Customer Type'),
dataCell: (value) => DataCell(Text('$value')),
),
WebDataColumn(
name: 'date',
label: const Text('Date & Time'),
dataCell: (value) => DataCell(Text('$value')),
),
WebDataColumn(
name: 'qty',
label: const Text('Qty'),
dataCell: (value) => DataCell(Text('$value')),
sortable: true,
),
WebDataColumn(
name: 'grand_total',
label: const Text('Grand Total'),
dataCell: (value) => DataCell(Text('$value')),
sortable: true,
),
],
rows: data),
header: Text(""),
You can simply add a widget to this package in each row. and this example used is in the same package with some changes to accept widget.
here is the example code
main.dart
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_web_data_table/web_data_table.dart';
import 'sample_data.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
#override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
late String _sortColumnName;
late bool _sortAscending;
List<String>? _filterTexts;
bool _willSearch = true;
Timer? _timer;
int? _latestTick;
List<String> _selectedRowKeys = [];
int _rowsPerPage = 10;
#override
void initState() {
super.initState();
_sortColumnName = 'browser';
_sortAscending = false;
_timer = Timer.periodic(Duration(seconds: 1), (timer) {
if (!_willSearch) {
if (_latestTick != null && timer.tick > _latestTick!) {
_willSearch = true;
}
}
if (_willSearch) {
_willSearch = false;
_latestTick = null;
setState(() {
if (_filterTexts != null && _filterTexts!.isNotEmpty) {
_filterTexts = _filterTexts;
print('filterTexts = $_filterTexts');
}
});
}
});
}
#override
void dispose() {
super.dispose();
_timer?.cancel();
_timer = null;
}
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('WebDataTable Sample'),
),
body: SingleChildScrollView(
child: Container(
padding: const EdgeInsets.all(8.0),
child: WebDataTable(
header: Text('Sample Data'),
actions: [
if (_selectedRowKeys.isNotEmpty)
SizedBox(
height: 50,
width: 100,
child: MaterialButton(
color: Colors.red,
child: Text(
'Delete',
style: TextStyle(
color: Colors.white,
),
),
onPressed: () {
print('Delete!');
setState(() {
_selectedRowKeys.clear();
});
},
),
),
Container(
width: 300,
child: TextField(
decoration: InputDecoration(
prefixIcon: Icon(Icons.search),
hintText: 'increment search...',
focusedBorder: const OutlineInputBorder(
borderSide: BorderSide(
color: Color(0xFFCCCCCC),
),
),
border: const OutlineInputBorder(
borderSide: BorderSide(
color: Color(0xFFCCCCCC),
),
),
),
onChanged: (text) {
_filterTexts = text.trim().split(' ');
_willSearch = false;
_latestTick = _timer?.tick;
},
),
),
],
source: WebDataTableSource(
sortColumnName: _sortColumnName,
sortAscending: _sortAscending,
filterTexts: _filterTexts,
columns: [
WebDataColumn(
name: 'id',
label: const Text('ID'),
dataCell: (value) => DataCell(Text('$value')),
),
WebDataColumn(
name: 'renderingEngine',
label: const Text('Rendering engine'),
dataCell: (value) => DataCell(Text('$value')),
),
WebDataColumn(
name: 'browser',
label: const Text('Browser'),
dataCell: (value) => DataCell(Text('$value')),
),
WebDataColumn(
name: 'platform',
label: const Text('Platform(s)'),
dataCell: (value) => DataCell(Text('$value')),
),
WebDataColumn(
name: 'engineVersion',
label: const Text('Engine version'),
dataCell: (value) => DataCell(Text('$value')),
),
WebDataColumn(
name: 'cssGrade',
label: const Text('CSS grade'),
dataCell: (value) => DataCell(Text('$value')),
sortable: false,
),
WebDataColumn(
name: 'dateTime',
label: const Text('DateTime'),
dataCell: (value) {
if (value is DateTime) {
final text =
'${value.year}/${value.month}/${value.day} ${value.hour}:${value.minute}:${value.second}';
return DataCell(Text(text));
}
return DataCell(Text(value.toString()));
},
filterText: (value) {
if (value is DateTime) {
return '${value.year}/${value.month}/${value.day} ${value.hour}:${value.minute}:${value.second}';
}
return value.toString();
}),
WebDataColumn(
name: 'btn',
label: const Text('btn'),
dataCell: (value) {
return DataCell(value);
},
filterText: (value) {
if (value is DateTime) {
return '${value.year}/${value.month}/${value.day} ${value.hour}:${value.minute}:${value.second}';
}
return value.toString();
}),
],
rows: SampleData().data,
selectedRowKeys: _selectedRowKeys,
onTapRow: (rows, index) {
print('onTapRow(): index = $index, row = ${rows[index]}');
},
onSelectRows: (keys) {
print('onSelectRows(): count = ${keys.length} keys = $keys');
setState(() {
_selectedRowKeys = keys;
});
},
primaryKeyName: 'id',
),
horizontalMargin: 100,
onPageChanged: (offset) {
print('onPageChanged(): offset = $offset');
},
onSort: (columnName, ascending) {
print(
'onSort(): columnName = $columnName, ascending = $ascending');
setState(() {
_sortColumnName = columnName;
_sortAscending = ascending;
});
},
onRowsPerPageChanged: (rowsPerPage) {
print('onRowsPerPageChanged(): rowsPerPage = $rowsPerPage');
setState(() {
if (rowsPerPage != null) {
_rowsPerPage = rowsPerPage;
}
});
},
rowsPerPage: _rowsPerPage,
),
),
),
),
);
}
}
sample_data.dart
import 'package:flutter/material.dart';
class SampleData {
List<Map<String, dynamic>> get data =>
sampleDataRows.map((row) => row.values).toList();
final List<SampleDataRow> sampleDataRows = [
SampleDataRow.fromList([
'010',
'Gecko',
'Firefox 3.0',
'Win 2k+ / OSX.3+',
'1.9',
'A',
'2020-10-10 13:30:30',
],MaterialButton(onPressed: (){},child: Text("Button"),color: Colors.red,)),
SampleDataRow.fromList([
'011',
'Gecko',
'Camino 1.0',
'OSX.2+',
'1.8',
'A',
'2020-10-10 13:30:30',
],MaterialButton(onPressed: (){},child: Text("Button"),color: Colors.blue,)),
SampleDataRow.fromList([
'012',
'Gecko',
'Camino 1.5',
'OSX.3+',
'1.8',
'A',
'2020-10-10 13:30:30',
],MaterialButton(onPressed: (){},child: Text("Button"),color: Colors.yellow,)),
SampleDataRow.fromList([
'013',
'Gecko',
'Netscape 7.2',
'Win 95+ / Mac OS 8.6-9.2',
'1.7',
'A',
'2020-10-10 13:30:30',
],MaterialButton(onPressed: (){},child: Text("Button"),)),
SampleDataRow.fromList([
'014',
'Gecko',
'Netscape Browser 8',
'Win 98SE+',
'1.7',
'A',
'2020-10-10 13:30:30',
],MaterialButton(onPressed: (){},child: Text("Button"),)),
SampleDataRow.fromList([
'015',
'Gecko',
'Netscape Navigator 9',
'Win 98+ / OSX.2+',
'1.8',
'A',
'2020-10-10 13:30:30',
],MaterialButton(onPressed: (){},child: Text("Button"),)),
SampleDataRow.fromList([
'016',
'Gecko',
'Mozilla 1.0',
'Win 95+ / OSX.1+',
'1',
'A',
'2020-10-10 13:30:30',
],MaterialButton(onPressed: (){},child: Text("Button"),)),
SampleDataRow.fromList([
'017',
'Gecko',
'Mozilla 1.1',
'Win 95+ / OSX.1+',
'1.1',
'A',
'2020-10-10 13:30:30',
],MaterialButton(onPressed: (){},child: Text("Button"),)),
SampleDataRow.fromList([
'018',
'Gecko',
'Mozilla 1.2',
'Win 95+ / OSX.1+',
'1.2',
'A',
'2020-10-10 13:30:30',
],MaterialButton(onPressed: (){},child: Text("Button"),)),
SampleDataRow.fromList([
'019',
'Gecko',
'Mozilla 1.3',
'Win 95+ / OSX.1+',
'1.3',
'A',
'2020-10-10 13:30:30',
],MaterialButton(onPressed: (){},child: Text("Button"),)),
SampleDataRow.fromList([
'020',
'Gecko',
'Mozilla 1.4',
'Win 95+ / OSX.1+',
'1.4',
'A',
'2020-10-10 13:30:30',
],MaterialButton(onPressed: (){},child: Text("Button"),)),
SampleDataRow.fromList([
'021',
'Gecko',
'Mozilla 1.5',
'Win 95+ / OSX.1+',
'1.5',
'A',
'2020-10-10 13:30:30',
],MaterialButton(onPressed: (){},child: Text("Button"),)),
SampleDataRow.fromList([
'022',
'Gecko',
'Mozilla 1.6',
'Win 95+ / OSX.1+',
'1.6',
'A',
'2020-10-10 13:30:30',
],MaterialButton(onPressed: (){},child: Text("Button"),)),
SampleDataRow.fromList([
'023',
'Gecko',
'Mozilla 1.7',
'Win 98+ / OSX.1+',
'1.7',
'A',
'2020-10-10 13:30:30',
],MaterialButton(onPressed: (){},child: Text("Button"),)),
SampleDataRow.fromList([
'024',
'Gecko',
'Mozilla 1.8',
'Win 98+ / OSX.1+',
'1.8',
'A',
'2020-10-10 13:30:30',
],MaterialButton(onPressed: (){},child: Text("Button"),)),
SampleDataRow.fromList([
'025',
'Gecko',
'Seamonkey 1.1',
'Win 98+ / OSX.2+',
'1.8',
'A',
'2020-10-10 13:30:30',
],MaterialButton(onPressed: (){},child: Text("Button"),)),
SampleDataRow.fromList([
'026',
'Gecko',
'Epiphany 2.20',
'Gnome',
'1.8',
'A',
'2020-10-10 13:30:30',
],MaterialButton(onPressed: (){},child: Text("Button"),)),
SampleDataRow.fromList([
'027',
'Webkit',
'Safari 1.2',
'OSX.3',
'125.5',
'A',
'2020-10-10 13:30:30',
],MaterialButton(onPressed: (){},child: Text("Button"),)),
SampleDataRow.fromList([
'028',
'Webkit',
'Safari 1.3',
'OSX.3',
'312.8',
'A',
'2020-10-10 13:30:30',
],MaterialButton(onPressed: (){},child: Text("Button"),)),
SampleDataRow.fromList([
'029',
'Webkit',
'Safari 2.0',
'OSX.4+',
'419.3',
'A',
'2020-10-10 13:30:30',
],MaterialButton(onPressed: (){},child: Text("Button"),)),
SampleDataRow.fromList([
'030',
'Webkit',
'Safari 3.0',
'OSX.4+',
'522.1',
'A',
'2020-10-10 13:30:30',
],MaterialButton(onPressed: (){},child: Text("Button"),)),
SampleDataRow.fromList([
'031',
'Webkit',
'OmniWeb 5.5',
'OSX.4+',
'420',
'A',
'2020-10-10 13:30:30',
],MaterialButton(onPressed: (){},child: Text("Button"),)),
SampleDataRow.fromList([
'032',
'Webkit',
'iPod Touch / iPhone',
'iPod',
'420.1',
'A',
'2020-10-10 13:30:30',
],MaterialButton(onPressed: (){},child: Text("Button"),)),
SampleDataRow.fromList([
'033',
'Webkit',
'S60',
'S60',
'413',
'A',
'2020-10-10 13:30:30',
],MaterialButton(onPressed: (){},child: Text("Button"),)),
SampleDataRow.fromList([
'034',
'Presto',
'Opera 7.0',
'Win 95+ / OSX.1+',
'-',
'A',
'2020-10-10 13:30:30',
],MaterialButton(onPressed: (){},child: Text("Button"),)),
SampleDataRow.fromList([
'035',
'Presto',
'Opera 7.5',
'Win 95+ / OSX.2+',
'-',
'A',
'2020-10-10 13:30:30',
],MaterialButton(onPressed: (){},child: Text("Button"),)),
SampleDataRow.fromList([
'036',
'Presto',
'Opera 8.0',
'Win 95+ / OSX.2+',
'-',
'A',
'2020-10-10 13:30:30',
],MaterialButton(onPressed: (){},child: Text("Button"),)),
SampleDataRow.fromList([
'037',
'Presto',
'Opera 8.5',
'Win 95+ / OSX.2+',
'-',
'A',
'2020-10-10 13:30:30',
],MaterialButton(onPressed: (){},child: Text("Button"),)),
SampleDataRow.fromList([
'038',
'Presto',
'Opera 9.0',
'Win 95+ / OSX.3+',
'-',
'A',
'2020-10-10 13:30:30',
],MaterialButton(onPressed: (){},child: Text("Button"),)),
SampleDataRow.fromList([
'039',
'Presto',
'Opera 9.2',
'Win 88+ / OSX.3+',
'-',
'A',
'2020-10-10 13:30:30',
],MaterialButton(onPressed: (){},child: Text("Button"),)),
SampleDataRow.fromList([
'040',
'Presto',
'Opera 9.5',
'Win 88+ / OSX.3+',
'-',
'A',
'2020-10-10 13:30:30',
],MaterialButton(onPressed: (){},child: Text("Button"),)),
SampleDataRow.fromList([
'041',
'Presto',
'Opera for Wii',
'Wii',
'-',
'A',
'2020-10-10 13:30:30',
],MaterialButton(onPressed: (){},child: Text("Button"),)),
SampleDataRow.fromList([
'042',
'Presto',
'Nokia N800',
'N800',
'-',
'A',
'2020-10-10 13:30:30',
],MaterialButton(onPressed: (){},child: Text("Button"),)),
SampleDataRow.fromList([
'043',
'Presto',
'Nintendo DS browser',
'Nintendo DS',
'8.5',
'C/A',
'2020-10-10 13:30:30',
],MaterialButton(onPressed: (){},child: Text("Button"),)),
SampleDataRow.fromList([
'044',
'KHTML',
'Konqureror 3.1',
'KDE 3.1',
'3.1',
'C',
'2020-10-10 13:30:30',
],MaterialButton(onPressed: (){},child: Text("Button"),)),
SampleDataRow.fromList([
'045',
'KHTML',
'Konqureror 3.3',
'KDE 3.3',
'3.3',
'A',
'2020-10-10 13:30:30',
],MaterialButton(onPressed: (){},child: Text("Button"),)),
SampleDataRow.fromList([
'046',
'KHTML',
'Konqureror 3.5',
'KDE 3.5',
'3.5',
'A',
'2020-10-10 13:30:30',
],MaterialButton(onPressed: (){},child: Text("Button"),)),
SampleDataRow.fromList([
'047',
'Tasman',
'Internet Explorer 4.5',
'Mac OS 8-9',
'-',
'X',
'2020-10-10 13:30:30',
],MaterialButton(onPressed: (){},child: Text("Button"),)),
SampleDataRow.fromList([
'048',
'Tasman',
'Internet Explorer 5.1',
'Mac OS 7.6-9',
'1',
'C',
'2020-10-10 13:30:30',
],MaterialButton(onPressed: (){},child: Text("Button"),)),
SampleDataRow.fromList([
'049',
'Tasman',
'Internet Explorer 5.2',
'Mac OS 8-X',
'1',
'C',
'2020-10-10 13:30:30',
],MaterialButton(onPressed: (){},child: Text("Button"),)),
SampleDataRow.fromList([
'050',
'Misc',
'NetFront 3.1',
'Embedded devices',
'-',
'C',
'2020-10-10 13:30:30',
],MaterialButton(onPressed: (){},child: Text("Button"),)),
SampleDataRow.fromList([
'051',
'Misc',
'NetFront 3.4',
'Embedded devices',
'-',
'A',
'2020-10-10 13:30:30',
],MaterialButton(onPressed: (){},child: Text("Button"),)),
SampleDataRow.fromList([
'052',
'Misc',
'Dillo 0.8',
'Embedded devices',
'-',
'X',
'2020-10-10 13:30:30',
],MaterialButton(onPressed: (){},child: Text("Button"),)),
SampleDataRow.fromList([
'053',
'Misc',
'Links',
'Text only',
'-',
'X',
'2020-10-10 13:30:30',
],MaterialButton(onPressed: (){},child: Text("Button"),)),
SampleDataRow.fromList([
'054',
'Misc',
'Lynx',
'Text only',
'-',
'X',
'2020-10-10 13:30:30',
],MaterialButton(onPressed: (){},child: Text("Button"),)),
SampleDataRow.fromList([
'055',
'Misc',
'IE Mobile',
'Windows Mobile 6',
'-',
'C',
'2020-10-10 13:30:30',
],MaterialButton(onPressed: (){},child: Text("Button"),)),
SampleDataRow.fromList([
'056',
'Misc',
'PSP browser',
'PSP',
'-',
'C',
'2020-10-10 13:30:30',
],MaterialButton(onPressed: (){},child: Text("Button"),)),
];
}
class SampleDataRow {
SampleDataRow._({
required this.id,
required this.renderingEngine,
required this.browser,
required this.platform,
required this.engineVersion,
required this.cssGrade,
required this.dateTime,
required this.btn,
});
factory SampleDataRow.fromList(List<String> values,Widget child) {
return SampleDataRow._(
id: values[0],
renderingEngine: values[1],
browser: values[2],
platform: values[3],
engineVersion: values[4],
cssGrade: values[5],
dateTime: DateTime.parse(values[6]),
btn: child,
);
}
final String id;
final String renderingEngine;
final String browser;
final String platform;
final String engineVersion;
final String cssGrade;
final Widget btn;
final DateTime dateTime;
Map<String, dynamic> get values {
return {
'id': id,
'renderingEngine': renderingEngine,
'browser': browser,
'platform': platform,
'engineVersion': engineVersion,
'cssGrade': cssGrade,
'dateTime': dateTime,
'btn': btn,
};
}
}
Related
In laravel how to seed existing databse using array?
I want to seed existing database in my application. here is db with data in it: I made array in seeder and now I want to assign those values to my fields with one loop I guess; This is migration: public function up() { Schema::create('products', function (Blueprint $table) { $table->char('maker'); $table->integer('model')->unique(); $table->string('type'); }); } And here is my seeder, I tried something but it isn't working. it says "Undefined array key "A"" public function run() { $array = ['A', 1232, 'PC', 'A', 1233, 'PC', 'A', 1276, 'Printer', 'A', 1298, 'Laptop', 'A', 1401, 'Printer', 'A', 1408, 'Printer', 'A', 1752, 'Laptop', 'B', 1121, 'PC', 'B', 1750, 'Laptop', 'C', 1321, 'Laptop', 'D', 1288, 'Printer', 'D', 1433, 'Printer', 'E', 1260, 'PC', 'E', 1434, 'Printer', 'E', 2112, 'PC', 'E', 2113, 'PC' ]; foreach ($array as $key => $item){ Product::create([ 'maker' => $array[$item], 'model' => $array[$item], 'type' => $array[$item] ]); } }
use this function for insert all data for($i=0;i<size_of($array);$i++){ if(($i%3)==0){ DB::table('products')->insert([ 'maker' =>$array[$i], 'model' => $array[$i+1], 'type' => $array[$i+2] ]); } }
Executing var video_overview = $('#upl_overview_id').summernote('code'); returns object not html text
My initialization: function init_video_summernote(id_val,my_placeholder,my_width,my_height) { $( id_val ).summernote('destroy'); $( id_val ).summernote( { placeholder: my_placeholder, //height: my_height, //width: my_width, toolbar: [ ['style', ['style']], ['font', ['bold', 'italic', 'underline', 'clear']], ['fontname', ['fontname']], ['para', ['ul', 'ol', 'paragraph']], ['height', ['height']], ['table', ['table']], ['view', ['fullscreen', 'codeview']], ['help', ['help']] ], lineHeights: ['1.0', '1.2', '1.4', '1.5', '1.6', '1.8', '2.0', '3.0'], fontNames: [ 'Arial', 'Arial Black', 'Comic Sans MS', 'Courier New', 'Helvetica Neue', 'Impact', 'Lucida Grande', 'Tahoma', 'Times New Roman', 'Verdana' ], styleTags: ['p', 'blockquote', 'pre', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6'], lang: { 'en-US': { font: { bold: 'Bold', italic: 'Italic', underline: 'Underline', clear: 'Remove Font Style', height: 'Line Height', name: 'Font Family' }, image: { image: 'Picture', insert: 'Insert Image', resizeFull: 'Resize Full', resizeHalf: 'Resize Half', resizeQuarter: 'Resize Quarter', floatLeft: 'Float Left', floatRight: 'Float Right', floatNone: 'Float None', shapeRounded: 'Shape: Rounded', shapeCircle: 'Shape: Circle', shapeThumbnail: 'Shape: Thumbnail', shapeNone: 'Shape: None', dragImageHere: 'Drag image here', dropImage: 'Drop image', selectFromFiles: 'Select from files', url: 'Image URL', remove: 'Remove Image' }, link: { link: 'Link', insert: 'Insert Link', unlink: 'Unlink', edit: 'Edit', textToDisplay: 'Text to display', url: 'To what URL should this link go?', openInNewWindow: 'Open in new window' }, table: { table: 'Table' }, hr: { insert: 'Insert Horizontal Rule' }, style: { style: 'Style', normal: 'Normal', blockquote: 'Quote', pre: 'Code', h1: 'Header 1', h2: 'Header 2', h3: 'Header 3', h4: 'Header 4', h5: 'Header 5', h6: 'Header 6' }, lists: { unordered: 'Unordered list', ordered: 'Ordered list' }, options: { help: 'Help', fullscreen: 'Full Screen', codeview: 'Code View' }, paragraph: { paragraph: 'Paragraph', outdent: 'Outdent', indent: 'Indent', left: 'Align left', center: 'Align center', right: 'Align right', justify: 'Justify full' }, color: { recent: 'Recent Color', more: 'More Color', background: 'Background Color', foreground: 'Foreground Color', transparent: 'Transparent', setTransparent: 'Set transparent', reset: 'Reset', resetToDefault: 'Reset to default' }, shortcut: { shortcuts: 'Keyboard shortcuts', close: 'Close', textFormatting: 'Text formatting', action: 'Action', paragraphFormatting: 'Paragraph formatting', documentStyle: 'Document Style' }, history: { undo: 'Undo', redo: 'Redo' } } } } ); } When I execute this code to get the html to store in a subsequent db insert. var video_overview = $('#upl_overview_id').summernote('code'); console.log('OVERVIEW:'+video_overview); This snippit of code is called from within a Dropzone sending event function. I get the following in the console output OVERVIEW:[object Object] Instead of the text to store in the DB any ideas what I am missing here?
Never mind this was caused by including summernote.js more than once
Ckeditor 4.10 FULL package not displaying color buttons
I have upgraded from ckeditor version 4.6.2 full package to 4.10 full package and the color buttons are not appearing. Here is my toolbar config: config.toolbar = [ { name: 'clipboard', items: ['Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'Undo', 'Redo'] }, { name: 'editing', items: ['Find', 'Replace', '-', 'SelectAll', '-', 'Scayt'] }, { name: 'tools', items: ['ShowBlocks'] }, { name: 'links', items: ['Link', 'Unlink', 'Anchor'] }, { name: 'insert', items: ['Image', 'Table', 'SpecialChar', 'Iframe'] }, { name: 'document', items: ['Source'] }, '/', { name: 'basicstyles', items: ['Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript', '-', 'CopyFormatting', 'RemoveFormat'] }, { name: 'colors', items: ['TextColor', 'BGColor'] }, { name: 'styles', items: ['Format', 'Font', 'FontSize'] }, { name: 'paragraph', items: ['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', '-', 'Blockquote', 'CreateDiv', '-', 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock', '-', 'BidiLtr', 'BidiRtl', ] }, ]; I am not getting any errors, is there a work around for this? This is a critical plugin for our platform.
How can I join these time-tables together using Ruby? [duplicate]
I have a couple time_tables in this array. There are four time_tables that are related to each other in a linear way by their start_location - end_location and start_date - end_date. When the first time_table ends, the other time_table starts, and so on. My code: arr = [ { name: 01, start_date: '2014-04-24 22:03:00', start_location: 'A', end_date: '2014-04-24 22:10:00', end_location: 'B' }, { name: 05, start_date: '2014-04-24 22:10:00', start_location: 'C', end_date: '2014-04-24 23:10:00', end_location: 'D' }, { name: 01, start_date: '2014-04-24 17:10:00', start_location: 'X', end_date: '2014-04-24 20:10:00', end_location: 'B' }, { name: 01, start_date: '2014-04-24 17:10:00', start_location: 'Z', end_date: '2014-04-24 20:10:00', end_location: 'B' }, { name: 06, start_date: '2014-04-24 20:15:00', start_location: 'B', end_date: '2014-04-24 22:10:00', end_location: 'C' }, { name: 03, start_date: '2014-04-24 23:15:00', start_location: 'D', end_date: '2014-04-24 00:10:00', end_location: 'E' } ] new_array = [] i = 0 while i <= 5 do if arr[i][:end_location] == arr[i+1][:start_location] && arr[i][:start_date] <= arr[i+1][:start_date] new_array << arr[i+1] end i = i + 1 end This is the result that I want: # My expexpected result will be this: # [ # { name: 01, start_date: '2014-04-24 22:03:00', start_location: 'A', end_date: '2014-04-24 22:10:00', end_location: 'B' }, # { name: 06, start_date: '2014-04-24 22:15:00', start_location: 'B', end_date: '2014-04-24 22:20:00', end_location: 'C' }, # { name: 05, start_date: '2014-04-24 22:20:00', start_location: 'C', end_date: '2014-04-24 23:10:00', end_location: 'D' }, # { name: 03, start_date: '2014-04-24 23:15:00', start_location: 'D', end_date: '2014-04-24 00:10:00', end_location: 'E' } # ] but my algorithm is seems to be bad. Thank you for insights to make this work.
Aren't you really looking for the longest linear sub sequent time tables ? I wanted to clarify that through comments but I didn't have the permission to comment. Also there is a difference between the value of start_date of B (and start_location B) in input and the output, so I'm assuming it's a mistake. I have written the solution considering you want to find the longest linear sub sequent time tables. require 'date' def getLLTT(time_tables) longest = [] time_tables.sort_by! do |time_table| DateTime.parse(time_table[:start_date]).to_time end 0.upto(time_tables.size-1) do |i| long_for_i = [time_tables[i]] 0.upto(i-1) do |j| j_end_date = DateTime.parse(longest[j][-1][:end_date]).to_time i_start_date = DateTime.parse(time_tables[i][:start_date]).to_time if j_end_date <= i_start_date if longest[j][-1][:end_location].eql? time_tables[i][:start_location] if longest[j].size + 1 > long_for_i.size long_for_i = longest[j] + [time_tables[i]] end end end end longest[i] = long_for_i end return longest[-1] end puts getLLTT(arr) So given the input : arr = [ { name: 01, start_date: '2014-04-24 22:03:00', start_location: 'A', end_date: '2014-04-24 22:10:00', end_location: 'B' }, { name: 05, start_date: '2014-04-24 22:10:00', start_location: 'C', end_date: '2014-04-24 23:10:00', end_location: 'D' }, { name: 01, start_date: '2014-04-24 17:10:00', start_location: 'X', end_date: '2014-04-24 20:10:00', end_location: 'B' }, { name: 01, start_date: '2014-04-24 17:10:00', start_location: 'Z', end_date: '2014-04-24 20:10:00', end_location: 'B' }, { name: 06, start_date: '2014-04-24 20:15:00', start_location: 'B', end_date: '2014-04-24 22:10:00', end_location: 'C' }, { name: 03, start_date: '2014-04-24 23:15:00', start_location: 'D', end_date: '2014-04-24 00:10:00', end_location: 'E' } ] The output will be : [ {:name=>1, :start_date=>"2014-04-24 17:10:00", :start_location=>"Z", :end_date=>"2014-04-24 20:10:00", :end_location=>"B"} {:name=>6, :start_date=>"2014-04-24 20:15:00", :start_location=>"B", :end_date=>"2014-04-24 22:10:00", :end_location=>"C"} {:name=>5, :start_date=>"2014-04-24 22:10:00", :start_location=>"C", :end_date=>"2014-04-24 23:10:00", :end_location=>"D"} {:name=>3, :start_date=>"2014-04-24 23:15:00", :start_location=>"D", :end_date=>"2014-04-24 00:10:00", :end_location=>"E"} ]
This will "join" your time series by consecutive end and start location. def span x; x[:end_location].ord - x[:start_location].ord; end def diff x, y; x[:start_location].ord - y[:start_location].ord; end arr = arr.sort_by { |x| [x[:start_location], span(x)] } prev = arr[0] arr = arr.slice_before { |e| prev, prev2 = e, prev diff(prev, prev2) != 0 }.to_a.map(&:first).chunk(&method(:span)).first[1] For example, I get arr.map { |x| [x[:start_location], x[:end_location] } => [["A", "B"], ["B", "C"], ["C", "D"], ["D", "E"]]
Aloha editor - contenthadler settings per editable not making any changes
I have multiple (6) editables with two different classes (.html_edit_simple, .html_edit_advanced) on website and I want to divide them by class and each to have its own contentHandler settings. But no matter what I try, only the default settings are loaded. The ones defined under window.Aloha.settings.contentHandler.handler.sanitize don't apply at all. The settings code that I use is the following: (function(window, undefined) { if (window.Aloha === undefined || window.Aloha === null) { window.Aloha = {}; } window.Aloha.settings = { sidebar: { disabled: true } }; window.Aloha.settings.contentHandler = { insertHtml: [ 'word', 'generic', 'oembed', 'sanitize' ], initEditable: [ 'sanitize' ], getContents: [ 'blockelement', 'sanitize', 'basic' ], sanitize: 'relaxed', // relaxed, restricted, basic, allows: { elements: ['strong', 'em', 'i', 'b', 'blockquote', 'br', 'cite', 'code', 'dd', 'div', 'dl', 'dt', 'em', 'i', 'li', 'ol', 'p', 'pre', 'q', 'small', 'strike', 'sub', 'sup', 'u', 'ul', 'h1', 'h2', 'h3', 'h4', 'h5', 'img', 'video', 'audio'] }, handler: { generic: { transformFormattings: false }, sanitize: { '.html_edit_simple': { elements: [ 'b', 'i', 'strong', 'em', 'strike', 'u', 'a' ] }, '.html_edit_advanced': { elements: [ 'b', 'i', 'strong', 'em', 'strike', 'u', 'a', 'br', 'p', 'h1', 'h2', 'h3', 'h4', 'h5', 'sub', 'sup', 'ul', 'ol', 'li', 'div', 'img', 'video', 'audio' ] } } } } })(window); I made a console log just before Aloha.ready and everything is loaded correctly. So where could be the issue.