I have am trying to implement something along the lines of
Slickgrid, column with a drop down select list?
my code is;
slick.editors.js ;
(function ($) {
// register namespace
$.extend(true, window, {
"Slick": {
"Editors": {
"Text": TextEditor,
"Integer": IntegerEditor,
"Date": DateEditor,
"YesNoSelect": YesNoSelectEditor,
"Checkbox": CheckboxEditor,
"PercentComplete": PercentCompleteEditor,
"LongText": LongTextEditor,
"SelectOption": SelectCellEditor
}
}
});
with the function defined futher down,
function SelectCellEditor(args) {
var $select;
var defaultValue;
var scope = this;
this.init = function () {
if (args.column.options) {
opt_values = args.column.options.split(',');
} else {
opt_values = "yes,no".split(',');
}
option_str = ""
for (i in opt_values) {
v = opt_values[i];
option_str += "<OPTION value='" + v + "'>" + v + "</OPTION>";
}
$select = $("<SELECT tabIndex='0' class='editor-select'>" + option_str + "</SELECT>");
$select.appendTo(args.container);
$select.focus();
};
this.destroy = function () {
$select.remove();
};
this.focus = function () {
$select.focus();
};
this.loadValue = function (item) {
defaultValue = item[args.column.field];
$select.val(defaultValue);
};
this.serializeValue = function () {
if (args.column.options) {
return $select.val();
} else {
return ($select.val() == "yes");
}
};
this.applyValue = function (item, state) {
item[args.column.field] = state;
};
this.isValueChanged = function () {
return ($select.val() != defaultValue);
};
this.validate = function () {
return {
valid: true,
msg: null
};
};
this.init();
}
Then in my CSHTML
var columns = [
{ id: "color", name: "Color", field: "color", options: "Red,Green,Blue,Black,White", editor: Slick.Editors.SelectOption },
{ id: "lock", name: "Lock", field: "lock", options: "Locked,Unlocked", editor: Slick.Editors.SelectOption },
];
var options = {
enableCellNavigation: true,
enableColumnReorder: false
};
$(function () {
var data = [];
for (var i = 0; i < 20; i++) {
data[i] = {
color: "Red",
lock: "Locked"
};
}
the grid shows and the colour is shown as if its a regular text in a cell, but no dropdown?.
The drop-down will appear only when you are editing that cell. Adding editable: true to your grid options should work I think.
Related
I have two completer. one for Math custom functions and another for string custom functions. i want to trigger string functions using (.)period and for ctrl_space for math function.
Now if i press (.) or ctrl_space, it showing all the functions. but i want differentiate between two of them.Thanks..
var stringFunctions = ["Trim","Length","ToLower","ToUpper","ToNumber","ToString"]
var mathFunctions = ["Abs","Ceil","Exp","Floor","Log","ln","Pow","Round","Sqrt","cos","sin","tan","cosh","sinh","tanh","acos","asin","atan","Max","Min","Sum","Std","Var","Average","Norm","Median"]
var myCompleter1 = {
// identifierRegexps: [/[a-zA-Z_0-9\.\$\-\u00A2-\uFFFF]/],
getCompletions: function(editor, session, pos, prefix, callback) {
console.info("myCompleter prefix:", this.prefix);
callback(
null,
myList.filter(entry=>{
return entry.includes(this.prefix);
}).map(entry=>{
return {
value: entry
};
})
);
}
}
var myCompleter2 = {
// identifierRegexps: [/[a-zA-Z_0-9\.\$\-\u00A2-\uFFFF]/],
getCompletions: function(editor, session, pos, prefix, callback) {
console.info("myCompleter prefix:", this.prefix);
callback(
null,
myList.filter(entry=>{
return entry.includes(this.prefix);
}).map(entry=>{
return {
value: entry
};
})
);
}
}
langTools.addCompleter(myCompleter1);
langTools.addCompleter(myCompleter2);```
You can check the text of the line in the completer to decide if it is after dot or not
var stringFunctions = ["Trim", "Length", "ToLower", "ToUpper", "ToNumber", "ToString"]
var mathFunctions = ["Abs", "Ceil", "Exp", "Floor", "Log", "ln", "Pow", "Round",
"Sqrt", "cos", "sin", "tan", "cosh", "sinh", "tanh", "acos", "asin", "atan",
"Max", "Min", "Sum", "Std", "Var", "Average", "Norm", "Median"
]
var myCompleter1 = {
getCompletions: function(editor, session, pos, prefix, callback) {
var line = session.getLine(pos.row)
var lineStart = line.slice(0, pos.column - prefix.length)
var myList = !/\.\s*$/.test(lineStart) ? mathFunctions : stringFunctions;
callback(null, myList.map(entry => {
return {
value: entry,
score: 1000
};
}));
}
}
var langTools = ace.require("ace/ext/language_tools")
langTools.addCompleter(myCompleter1);
var editor = ace.edit("editor", {
maxLines: 20,
minLines: 5,
enableBasicAutocompletion: true,
enableSnippets: true,
enableLiveAutocompletion: false,
})
// automatically open popup after dot or word characters
var doLiveAutocomplete = function(e) {
var editor = e.editor;
var hasCompleter = editor.completer && editor.completer.activated;
if (e.command.name === "insertstring") {
// Only autocomplete if there's a prefix that can be matched
if (/[\w.]/.test(e.args)) {
editor.execCommand("startAutocomplete")
}
}
};
editor.commands.on('afterExec', doLiveAutocomplete);
<script src=https://ajaxorg.github.io/ace-builds/src-noconflict/ace.js></script>
<script src=https://ajaxorg.github.io/ace-builds/src-noconflict/ext-language_tools.js></script>
<div id=editor></div>
I need to export all data in datatable, so for that i have added ajax call in action for the export button, when i click on export button it fire the ajax call and also getting all the data in the response but after that ajax call in console i am getting error TypeError: a is undefined, can anyone please help me to resolve this issue, here is my code for that
Jquery :
function cmpTable() {
var buttonCommon = {
exportOptions: {
format: {
body: function (data, row, column, node) {
if (column == '1' || column == '2' || column == '3') {
var data = data.replace(/(<([^>]+)>)/ig, "")
data = data.replace('$', '');
return data.replace('%', '');
} else {
var data = data.replace(/(<([^>]+)>)/ig, "")
return data;
}
}
}
}
};
var branch = $("#branch").val();
var soc_start_date = $("#soc_start_date").val();
var soc_end_date = $("#soc_end_date").val();
var ot_start_range = $("#ot_start_range").val();
var ot_end_range = $("#ot_end_range").val();
var ep_start_range = $("#ep_start_range").val();
var ep_end_range = $("#ep_end_range").val();
var st_start_range = $("#st_start_range").val();
var st_end_range = $("#st_end_range").val();
var hha_start_range = $("#hha_start_range").val();
var hha_end_range = $("#hha_end_range").val();
var total_start_range = $("#total_start_range").val();
var total_end_range = $("#total_end_range").val();
var msw_start_range = $("#msw_start_range").val();
var msw_end_range = $("#msw_end_range").val();
var sn_start_range = $("#sn_start_range").val();
var sn_end_range = $("#sn_end_range").val();
var icd_start_range = $("#icd_start_range").val();
var icd_end_range = $("#icd_end_range").val();
var pt_start_range = $("#pt_start_range").val();
var pt_end_range = $("#pt_end_range").val();
var ep_end_start_range = $("#ep_end_start_range").val();
var ep_end_end_range = $("#ep_end_end_range").val();
var random_episode = $("#random_episode").val();
var page_length = 10;
if (random_episode != '') {
page_length = random_episode;
}
$('#cmp_table2').DataTable({
dom: 'Bfrtip',
searching: false,
"pageLength": page_length,
"processing": true,
"serverSide": true,
"aaSorting": [[ 3, "asc" ], [ 4, "asc" ]],
"destroy":true,
'ajax': {
"url": '<?php echo site_url('adhoc/adhoc_data'); ?>',
"type": 'POST',
data: {
branch: branch,
soc_start_date:soc_start_date,
soc_end_date:soc_end_date,
ot_start_range:ot_start_range,
ot_end_range:ot_end_range,
ep_start_range:ep_start_range,
ep_end_range:ep_end_range,
st_start_range:st_start_range,st_end_range:st_end_range,
hha_start_range : hha_start_range,
hha_end_range:hha_end_range,total_start_range:total_start_range,
total_end_range:total_end_range,
msw_start_range:msw_start_range,msw_end_range:msw_end_range,
sn_start_range : sn_start_range,sn_end_range:sn_end_range,icd_start_range:icd_start_range,
icd_end_range:icd_end_range,pt_start_range:pt_start_range,pt_end_range:pt_end_range,
ep_end_start_range:ep_end_start_range,ep_end_end_range:ep_end_end_range,random_episode:random_episode
},
},
"columns": [
{ "data": "display_name"},
{ "data": "LastName"},
{ "data": "MRN"},
{ "data": "SOCDate"},
{ "data": "EpStart"},
{ "data": "EpEnd"},
{ "data": "ICD"},
{ "data": "PhyLastName"},
{ "data": "SNVisits"},
{ "data": "HHAVisits"},
{ "data": "MSWVisits"},
{ "data": "PTVisits"},
{ "data": "OTVisits"},
{ "data": "STVisits"},
{ "data": "TotVisits"},
],
buttons: [
$.extend(true, {}, buttonCommon, {
extend: 'excelHtml5',
className: 'start_class',
text: 'Export',
title: 'Target Starting Episodes',
action: function (e, dt, node, config) {
$.ajax({
url: '<?php echo site_url('adhoc/adhoc_data'); ?>',
method: 'POST',
data: {
branch: branch,
soc_start_date:soc_start_date,
soc_end_date:soc_end_date,
ot_start_range:ot_start_range,
ot_end_range:ot_end_range,
ep_start_range:ep_start_range,
ep_end_range:ep_end_range,
st_start_range:st_start_range,st_end_range:st_end_range,
hha_start_range : hha_start_range,
hha_end_range:hha_end_range,total_start_range:total_start_range,
total_end_range:total_end_range,
msw_start_range:msw_start_range,msw_end_range:msw_end_range,
sn_start_range : sn_start_range,sn_end_range:sn_end_range,icd_start_range:icd_start_range,
icd_end_range:icd_end_range,pt_start_range:pt_start_range,pt_end_range:pt_end_range,
ep_end_start_range:ep_end_start_range,ep_end_end_range:ep_end_end_range,random_episode:random_episode,
type : 'all'
}
}).then(function (ajaxReturnedData) {
dt.rows.add(ajaxReturnedData.data).draw();
$.fn.dataTable.ext.buttons.excelHtml5.action.call(this, e, dt, node, config);
});
}
}),
]
});
}
Controller Action :
if(is_use_azure()) {
$otherdb->select('tb_Branch.description as display_name,LastName,MRN,SOCDate,EpStart,EpEnd,ICD,PhyLastName,SNVisits,HHAVisits,MSWVisits,PTVisits,
OTVisits,STVisits,TotVisits');
$otherdb->from('tb_Episode, tb_Branch');
if ($is_random_episodes) {
$otherdb->order_by("RAND()");
} else {
$otherdb->order_by($column_name,$order_dir);
}
$otherdb->limit($limit,$offset);
if($where !='') {
$otherdb->where($where,NULL, FALSE);
}
if($branch !='') {
//$otherdb->where_in('BranchID',$_POST['branch'],false);
}
$episode_data = $otherdb->get();
$episode_data = $episode_data->result_array();
$otherdb->select('count(*) as total');
$otherdb->from('tb_Episode, tb_Branch');
if($where !='') {
$otherdb->where($where,NULL, FALSE);
}
if($branch !='') {
$otherdb->where_in('BranchID',$_POST['branch'],false);
}
$count_data = $otherdb->get();
//echo $otherdb->last_query(); die;
$count_data = $count_data->result_array();
} else {
$this->db->select('tb_Branch.description as display_name,LastName,MRN,SOCDate,EpStart,EpEnd,ICD,PhyLastName,SNVisits,HHAVisits,MSWVisits,PTVisits,
OTVisits,STVisits,TotVisits');
$this->db->from('tb_Episode, tb_Branch');
if ($is_random_episodes) {
$this->db->order_by("RAND()");
} else {
$this->db->order_by($column_name,$order_dir);
}
if(isset($_POST['type']) && $_POST['type'] == 'all') {
} else {
$this->db->limit($limit,$offset);
}
if($where !='') {
$this->db->where($where,NULL, FALSE);
}
if($branch !='') {
$this->db->where_in('BranchID',$_POST['branch']);
}
$episode_data = $this->db->get();
$episode_data = $episode_data->result_array();
$this->db->select('count(*) as total');
$this->db->from('tb_Episode, tb_Branch');
if($where !='') {
$this->db->where($where,NULL, FALSE);
}
if($branch !='') {
$this->db->where_in('BranchID',$branch);
}
$count_data = $this->db->get();
$count_data = $count_data->result_array();
}
$random_episode = $count_data[0]['total'];
if(isset($_POST['random_episode']) && (int)$_POST['random_episode'] && $_POST['random_episode'] != 0) {
$random_episode = $_POST['random_episode'];
}
$total_data = $random_episode;
if(isset($_POST['type']) && $_POST['type'] == 'all') {
echo json_encode(array('draw'=>$_POST['draw'],'recordsTotal'=>$total_data,'recordsFiltered'=>$total_data,'data'=>$episode_data));
} else {
echo json_encode(array('draw'=>$_POST['draw'],'recordsTotal'=>$total_data,'recordsFiltered'=>$total_data,'data'=>$episode_data));
}
die;
I would like to add class "text-justify" automatically to every p, anyone know how to do this?
Now I am using this code:
CKEDITOR.on('dialogDefinition', function (ev) {
var dialogName = ev.data.name;
var dialogDefinition = ev.data.definition;
if (dialogName == 'table' || dialogName == 'tableProperties') {
var info = dialogDefinition.getContents('info');
// Remove fields
var cellSpacing = info.remove('txtCellSpace');
var cellPadding = info.remove('txtCellPad');
var border = info.remove('txtBorder');
var width = info.remove('txtWidth');
var height = info.remove('txtHeight');
var align = info.remove('cmbAlign');
}
});
$('#content, #longContent').ckeditor({
contentsCss: '/CMS/style_ckeditor.css',
allowedContent: true,
extraPlugins: 'button,menubutton,htmlbuttons,menu,floatpanel,panel',
htmlbuttons: [
{
name:'button1',
icon:'icon1.png',
html:'<p class="act-left">Sekretarz Zgromaczenia<br /><strong>Alfred Błaszczyk</strong></p><p class="act-right">Przewodniczący Zgromadzenia<br /><strong>Tomasz Radomski</strong></p><div class="clearfix"></div>',
title:'Dodaj podpisy'
},
{
name:'button2',
icon:'icon3.png',
html:'<ol class="law"><li> <ol><li>tekst</li></ol></li></ol>',
title:'Dodaj paragraf'
}
]
}).ckeditorGet().on('insertElement', function (event) {
var el = event.data;
if (el.is('table')) {
$(event.data.$)
.addClass('table table-bordered table-striped')
.removeAttr('cellpadding cellspacing')
.wrap('<div class="table-responsive"></div>');
}
}, null, null, 20);
It works for adding classes for table, but when I would like to do similar to P, it didn't work.
just use :
$('#content').ckeditor({
on: {
instanceReady: function () {
this.dataProcessor.htmlFilter.addRules({
elements: {
ul: function (el) {
el.addClass('ul');
},
table: function (el) {
el.addClass('entry');
}
}
});
}
}
});
For Ckeditor4
Is there a way to disable the keyboard events on Kendo UI Slider? Basically, I want to prevent changing the value of the slider when pressing left and right arrow keys. Is this possible at all?
Please note that slider is being dynamically inserted into the DOM as part of a KO custom binding handler.
ko.bindingHandlers.tone = {
init: function(element, valueAccessor) {
if (valueAccessor().settingToneEnabled) {
var $el = $(element);
var tag = '<span class="dropdown mrgn-tp-md"><ul class="dropdown-menu dropdown-menu-right text-center pddng-sm" aria-labelledby="tonedropdownMenu"><li class="pddng-lft-md pddng-rght-sm"><span id="tone-slider" title="tone"></span></li><li class="pddng-rght-sm"><i class="icon icon-delete"></i> ' + i18n['ps-deleteArticleToneLabel'] + '</li></ul></span>';
$(tag).appendTo($el);
var $slider = $('#tone-slider', $el);
var $delLink = $('a.del', $el);
var $dropdown = $('span.dropdown', $el);
$('a.dropdown-toggle', $dropdown).on('click', function() {
$('.dropdown-menu', $dropdown).toggle();
});
$slider.kendoSlider({
change: function(e) {
var va = valueAccessor();
va.value(e.value);
if ($.isFunction(va.handleUserInput)) {
va.handleUserInput();
}
},
showButtons: false,
min: -1,
max: 1,
smallStep: 1,
value: valueAccessor().value() || 0,
tickPlacement: 'none',
tooltip: {
enabled: false
}
});
$('.k-draghandle', $el).off('keydown');
$delLink.on('click', function(e) {
e.preventDefault();
if ($delLink.attr('disabled')) {
return;
}
var va = valueAccessor();
va.value(null);
if ($.isFunction(va.handleUserInput)) {
va.handleUserInput();
}
});
$el.data('slider', $slider.data("kendoSlider"));
$el.data('deleteButton', $delLink);
$el.data('dropdown', $dropdown);
} else {
$('<span href="" data-tone></span>').appendTo(element);
}
},
update: function(element, valueAccessor) {
var toneValues = {
'1': {
name: i18n['ps-tonePositive'],
val: 1,
css: 'icon-tone-positive'
},
'0': {
name: i18n['ps-toneNeutral'],
val: 0,
css: 'icon-tone-neutral'
},
'-1': {
name: i18n['ps-toneNegative'],
val: 0,
css: 'icon-tone-negative'
},
};
var $tone = $('*[data-tone]', element);
var val = valueAccessor().value() || 0;
var tone = toneValues[val.toString()] || toneValues['0'];
$tone.removeClass()
.addClass('icon').addClass(tone.css)
.attr('title', tone.name);
if (valueAccessor().settingToneEnabled) {
$('#tone-slider', element).data("kendoSlider").value(val);
}
},
};
You can try to remove the keydown handler.
See demo.
I have a grid in ext with some custom columns, and I want to be able to sort this column - I want to sort it by what is displayed inside of it, but really I just cannot figure out how to define a sorter for a column that will not be based on the dataIndex - I tried using a custom model, but I could not get that to work.
{
text: 'Parent',
dataIndex: 'Parent',
renderer: function(value, meta, record) {
var ret = record.raw.Parent;
if (ret) {
return ret.Name;
} else {
meta.tdCls = 'invisible';
return record.data.Name;
}
},
sortable: true
},
You should be able to override the doSort method of the column. Here's the gist of it. I also created a working fiddle (http://jsfiddle.net/cfarmerga/LG5uA/). The fiddle uses the string length of a field as the property to sort on, but of course you could apply your own custom sort logic.
var grid = Ext.create('Ext.grid.Panel',{
//...
columns: [
{ text: 'name', dataIndex: 'name', sortable: true },
{
text: 'Custom',
sortable : true,
dataIndex: 'customsort',
doSort: function(state) {
var ds = this.up('grid').getStore();
var field = this.getSortParam();
ds.sort({
property: field,
direction: state,
sorterFn: function(v1, v2){
v1 = v1.get(field);
v2 = v2.get(field);
return v1.length > v2.length ? 1 : (v1.length < v2.length ? -1 : 0);
}
});
}
}
]
//....
});
For Ext JS version 5, it looks like doSort was taken out, so I couldn't override that. Instead, I went the route of listening to the sortchange event, and from there, I used the Ext.data.Store.setSorters method. The code is a bit custom, and overly complex because of the data that I'm using, so keep that in mind (Fiddle here):
// grid class
initComponent: function() {
...
this.on('sortchange', this.onSortChange, this);
},
onSortChange: function(container, column, direction, eOpts) {
// check for dayColumnIndex
if (column && column.dayColumnIndex !== undefined) {
this.sortColumnByIndex(column.dayColumnIndex, direction);
}
},
sortColumnByIndex: function(columnIndex, direction) {
var store = this.getStore();
if (store) {
var sorterFn = function(rec1, rec2) {
var sortValue = false;
if (rec1 && rec2) {
var day1;
var daysStore1 = rec1.getDaysStore();
if (daysStore1) {
day1 = daysStore1.getAt(columnIndex);
}
var day2;
var daysStore2 = rec2.getDaysStore();
if (daysStore2) {
day2 = daysStore2.getAt(columnIndex);
}
if (day1 && day2) {
var val1 = day1.get('value');
var val2 = day2.get('value');
sortValue = val1 > val2 ? 1 : val1 === val2 ? 0 : -1;
}
}
return sortValue;
};
if (direction !== 'ASC') {
sorterFn = function(rec1, rec2) {
var sortValue = false;
if (rec1 && rec2) {
var day1;
var daysStore1 = rec1.getDaysStore();
if (daysStore1) {
day1 = daysStore1.getAt(columnIndex);
}
var day2;
var daysStore2 = rec2.getDaysStore();
if (daysStore2) {
day2 = daysStore2.getAt(columnIndex);
}
if (day1 && day2) {
var val1 = day1.get('value');
var val2 = day2.get('value');
sortValue = val1 < val2 ? 1 : val1 === val2 ? 0 : -1;
}
}
return sortValue;
};
}
store.setSorters([{
sorterFn: sorterFn
}]);
}
}
There is a convert method on the Ext.data.Model class that allows you to convert the data before it's being used. Then you can just specify this 'dataIndex' in your column and do a normal sort. The column will be sorted by that converted value. Here is the a sample model with just one field (Parent) and with it's corresponding conversion:
Ext.define('MyModel', {
extend: 'Ext.data.Model',
fields: [
{name: 'Parent', type: 'string', convert: sortParent},
// other fields...
],
sortParent: function(value, record) {
var ret = record.raw.Parent;
if (ret) {
return ret.Name;
} else {
meta.tdCls = 'invisible';
return record.data.Name;
}
}
});