Prevent sorting on clicking Input Field in Data Table not working - datatable

I am using DataTable to display my Data.
Issue
Each Column has a Search Field in the Head. But when I click on the input field, it keeps sorting every time I click inside the input field.
This is what I need
On Clicking, I don't want the sorting through input box.
What I have tried isn't working
<script type="text/javascript">
$(document).ready(function() {
// Setup - add a text input to each footer cell
$('#example thead th').each( function () {
var title = $(this).text();
$(this).html( '<input type="text" placeholder="Search '+title+'" />' );
} );
var table = $('#example').DataTable({
"pageLength": 20,
initComplete: function () {
this.api().columns().every( function () {
var that = this;
$( 'input', this.header() ).on( 'keyup change clear', function () {
if ( that.search() !== this.value ) {
that.search( this.value ).draw();
}
});
} );
}
});
} );
</script>
Please help.

To do this you can use 2 rows in the header:
the first one to control ordering/sorting
another one to display each input field
Then you need to use the orderCellsTop option to specify that only the first row should be used to control sorting.
A basic example, would therefore be as follows:
$(document).ready(function() {
$("#result-table thead tr").clone(true).appendTo("#result-table thead");
// add a text input filter to each column of the new row
$("#result-table thead tr:eq(1) th").each(function (i) {
var title = $(this).text();
$(this).html("<input type='text' class='form-control' placeholder='Search '" + title + "' />");
$("input", this).on( "keyup change", function () {
if ($("#result-table").DataTable().column(i).search() !== this.value) {
$("#result-table").DataTable().column(i).search(this.value).draw();
}
});
});
$('#example').DataTable({
orderCellsTop: true,
});
} );

Related

Ajax query not working after page is reloaded

I have 2 ajax query as below, and both the ajax query is working on the initial page loading, after loading data using 1st AJAX query the 2nd ajax query does not work after the page content is loaded, so request your help and advice as to home to resolve this issue such that both the ajax query works after every page load.
Ajax Query : 1
<script type="text/javascript">
$(document).ready(function(){
$("input[type='radio']").on('click', function(){
var radioValue = $("input[name='Gender']:checked").val();
var surl = '/fdata/' + radioValue;
var dsurl = encodeURI(surl, "UTF-8");
var hurl = '/Summary';
var dhurl = encodeURI(hurl, "UTF-8");
if (radioValue == "Male" ) { $('#DGender').load('dsurl #DGender'); };
if (radioValue == "Female" ) { $('#DGender').load('dsurl #DGender'); };
if (radioValue == "Summary" ) { $('#DGender').load('dhurl #summary'); };
});
});
</script>
Ajax Query : 2
<script type="text/javascript">
$(document).ready(function() {
// Setup - add a text input to each footer cell
$('input[type=search]').val('');
$('#DGender thead tr').clone(true).appendTo( '#DGender thead' );
$('#DGender thead tr:eq(1) th').each( function (i) {
var title = $(this).text();
$(this).html( '<input type="text" placeholder="'+title+'" />' );
$( 'input', this ).on( 'keyup change', function () {
if ( table.column(i).search() !== this.value ) {
table
.column(i)
.search( this.value )
.draw();
}
} );
} );
var table = $('#DGender').DataTable( {
ordering: false,
orderCellsTop: true,
fixedHeader: true,
filter: false,
searching: true,
info: false,
paging: false,
scrollX: "80vh",
scrollCollapse: false
});
} );
</script>
From,
Vino

Issue for the "change" event of "select" in ToolTipDialog execution times

Why Select change event execution times will increase with the number of button's click.
HTML :
<button id="btn">click me</button>
JS
require(["dojo/_base/declare", "dojo/dom", "dojo/on", "dojo/_base/lang", "dijit/registry", "dijit/TooltipDialog", "dijit/popup","dijit/form/Select", "dojo/_base/array", "dojo/domReady!"],
function(declare, dom, on, lang, registry, TooltipDialog, popup,Select, Array) {
var InfoWindow= declare( // 类名省略
TooltipDialog,
{
constructor: function (parameters) {
console.log("hello");
},
test:function(){
var tNode=dom.byId("btn");
var myTooltipDialog = new TooltipDialog({
id: 'myTooltipDialog',
style: "width: 300px;",
content: '<div id="tpDialog006" class="pDlg"></div><div id="selectMenu" class="right"><select name="select1" id="sel006" data-dojo-type="dijit/form/Select"> <option value="037" selected="selected">1</option><option class="left" value="005" >2</option><option class="left" value="007" >3</option><option value="006">4</option></select></div>',
onMouseLeave: function(e){
if(registry.getEnclosingWidget(e.target).name=="select1")
return;
popup.close(myTooltipDialog);
},
onOpen:lang.hitch(this, function(e) {
})
});
var sHu = registry.byId("sel006" );
sHu.on("change", function (e) {
alert( "value is" +sHu.value);
});
on(tNode,"click",function(){
popup.open({
popup: myTooltipDialog,
around: dom.byId('btn')
});
})
this.m1="t1";
}
}
);
var infoWindow = new InfoWindow({
});
infoWindow.test();
});
The code is at the link:code link
there may be some problem for the tooltipdialog shows but it will not affect the issue to be reproduced.
This is normal that the click is reproduced because :
in the button click (above) :
on(tNode,"click",function(){
popup.open({
popup: myTooltipDialog,
around: dom.byId('btn')
});
})
In every button click you are opening the Popup so, the tooltip's open function is being executed ( onOpen event fired ) which means that the change event is attached again to your sel006 select input .
What I propose to you is not to assign the select change event inside the tooltips onOpen event and just declare it after the toolTip initialization
So the code became :
var myTooltipDialog = new TooltipDialog({
id: 'myTooltipDialog',
style: "width: 300px;",
content: '<div id="tpDialog006" class="pDlg"></div><div id="selectMenu" class="right"><select name="select1" id="sel006" data-dojo-type="dijit/form/Select"> <option value="037" selected="selected">1</option><option class="left" value="005" >2</option><option class="left" value="007" >3</option><option value="006">4</option></select></div>',
onMouseLeave: function(e){
if(registry.getEnclosingWidget(e.target).name=="select1")
return;
popup.close(myTooltipDialog);
},
onOpen:lang.hitch(this, function(e) {
// remove event from here
})
});
var sHu = registry.byId("sel006" );
sHu.on("change", function (e) {
alert( "value is" +sHu.value);
});
Bellow a fiddle example : Fiddle

Kendo Custom Widget Filter

I am trying to build a custom widget that I can use as a custom filter in the Kendo grid. What I would like to do is have multiple input boxes that get concatenated back into a single string. The control below replaces the current inputbox but I am having trouble binding the value from my custom widget back to the filter. Is there something I am missing?
(function () {
var ui = window.kendo.ui,
Widget = ui.Widget;
var CustomFilter = Widget.extend({
init: function (element, options) {
var that = this;
Widget.fn.init.call(that, element, options);
var e = $(element);
e.wrap("<span></span>");
e.parent().append('<input type="text" style="width:3em;" />');
e.parent().append('<input type="text" style="width:3em;" />');
e.parent().on('keyup', 'input', function () {
//Set Value?
});
e.hide();
},
options: {
name: "CustomFilter"
}
});
ui.plugin(CustomFilter);
}());
var columns = [{ 'field': 'FieldName', title: 'FieldName', filterable: { ui: "customfilter" } } ];

How to set Row data using rowid and column name in jQgrid

I've added a custom icon using below code in jqgrid Actions column. When the cutom icon is clicked, a pop up is opened with Textarea, Save and Close buttons. When I click Save button I wanted to save the text entered in textarea to a hidden field column in jQgrid. I tried 'setRowData' and 'setCell' properties but nothing works. Am I missing something here?
afterInsertRow: function (rowid, rowdata, rowelem) {
$(this).triggerHandler("afterInsertRow.jqGrid", [rowid, rowdata, rowelem]);
//...//
//Start: Code for Notes Icon in Actions column
var iCol = getColumnIndexByName(grid, 'actions');
$(this).find(">tbody>tr#" + rowid + ">td:nth-child(" + (iCol + 1) + ")")
.each(function () {
$("<div>", {
title: "Custom",
mouseover: function () {
$(this).addClass('ui-state-hover');
},
mouseout: function () {
$(this).removeClass('ui-state-hover');
},
click: function (eve) {
$("#change_dialog").dialog({
buttons: {
'Save': function () {
var selRow = $(eve.target).closest("tr.jqgrow").attr("id");
var txtNotes = $("#mytext").val();
$("#gridJQ").setRowData(selRow, { 'notesHidden': txtNotes });
$("#gridJQ").jqGrid('setCell', selRow, 'notesHidden', txtNotes);
$("#gridJQ").jqGrid('setRowData', selRow, 'notesHidden', txtNotes);
$(this).dialog("close");
},
'Close':function() {
$(this).dialog("close");
}
}
});
return false;
}
}
).css({ "margin-right": "5px", float: "left", cursor: "pointer" })
.addClass("ui-pg-div ui-inline-custom")
.append('<span class="ui-icon ui-icon-document"></span>')
.prependTo($(this).children("div"));
});
Instead of using this code to get the row
var selRow = $(eve.target).closest("tr.jqgrow").attr("id");
Try something a more direct such as
var selRow = $("#gridJQ").jqGrid('getGridParam', 'selrow');
Or even just var selRow = rowid.
Does that help at all?

Ckeditor Get Content From Iframe

I have a iframe and i'm trying to use Dialog to get data in Iframe and output to current html, but i don't know how to get Ckeditor Content from the Iframe.
I tried to using CKEDITOR.instances['editor'].getData(); but look like cannot get it.
This is my code:
<textarea class='editor' name='description' id='description'></textarea>
$( "#dialog_custom" ).dialog({
autoOpen: false,
modal: true,
height: 768,
width: 1024,
buttons: {
Add: function() {
var model = $('.dialog_custom').contents().find('#model').val();
var product_id = $('.dialog_custom').contents().find('#product_id').val();
var product_name = $('.dialog_custom').contents().find('#product_name').val();
var qty = $('.dialog_custom').contents().find('#qty').val();
var total = $('.dialog_custom').contents().find('#total').val();
var category = $('.dialog_custom').contents().find('#category').val();
if(qty=='') { qty = '0'; }
if(total=='') { total = '0.00'; }
if(model=='') {
alert('Please input the correct Model Number.');
} else {
$(".product").append(InsertTableGetFromIframe);
$('.delete_custom_row').click(function() {
if(confirm("Are you sure want to delete this data?")) {
$(this).parents('.custom_row').next('.parts_row').remove();
$(this).parents('.custom_row').remove();
}
});
$('.dialog_custom').contents().find('#model').val('');
$('.dialog_custom').contents().find('#product_id').val('');
$('.dialog_custom').contents().find('#product_name').val('');
$('.dialog_custom').contents().find('#qty').val('');
$('.dialog_custom').contents().find('#total').val('');
$('.dialog_custom').contents().find('#category').val('');
$(this).dialog("close");
i++;
}
},
Close: function() {
$(this).dialog("close");
}
}
});
$( "#open_custom" ).click(function() {
$( "#dialog_custom" ).dialog( "open" );
});
</script>
Finally, I found out the solution to get the content in the iframe, i used jquery to submit the form then POST the value on the field and get it by Jquery again.
It's the most simple way that i found, actually I think we have another way better to do it...

Resources