Datatable search filter - datatable

I have datatable like these
var table = $("#tbl_multipoinfo");
var filter = $('.form-filterpo');
var target = table.attr('data-table');
$("#pideldate").datepicker({
dateFormat: 'yy-mm-dd'
});
var oTable = table.on( 'processing.dt', function ( e, settings, processing ) {
if (processing) {
$(this).find('tbody').addClass('load1 csspinner');
} else{
$(this).find('tbody').removeClass('load1 csspinner');
};
} ).DataTable({
"ajax": host+'datatable/'+target,
"bServerSide": true,
"order": [[ 1, "desc" ]],
"bFilter" : true,
"scrollY": "200px",
"scrollCollapse": true,
"paging": false,
"paging": false,
"ordering": false
});
But my problem is i'm stuck on seacrh filter (functional DATATABLE), even i'm trying typing anything still wont work at all, i try use code like these
$('.dataTables_filter input').unbind().keyup(function(e) {
var value = $(this).val();
if (value.length>0) {
oTable.search(value).draw();
} else {
//optional, reset the search if the phrase
//is less then 3 characters long
oTable.search('').draw();
}
});
But it wont let me filtered, is still same result. I might missing something, so can anyone help me these issue??

I found the solution, i change my code on Datatable
on
"bServerSide": true,
i removed it, and i put another input like these
<form class="form-filterpo" role="form">
<div class="row">
<div class="col-md-3 pull-right" style="padding-bottom:5px;">
<label>PO : </label>
<input id="fPono" class="form-control input-sm" type="text">
</div>
</div>
</form>
And add these on jquery (same at jquery my table)
$('#tbl_multipoinfo_filter').remove();
filter.find('#fPono').keyup(function(){
var fPono = $(this).val();
oTable.columns(1).search(fPono).draw();
});
And it work perfectly.
NB : If u do server side try put query instead on where, for my case i don't use query cause my query instead temporary need check list on each row.

Related

fullpage.js dynamically added sections: how to scroll inside the sections

I am adding the sections in HTML using JS from this object:
var slidesArray = [
{
'id': 1,
'title': '1 title',
},
{
'id': 2,
'title': '2 title',
},
{
'id': 3,
'title': '3 title',
},
{
'id': 4,
'title': '4 title',
}
];
like this:
var $container = $('#fullpage'),
shuffledItems = "",
shuffledItemsTemplate =
"<div class='section fp-scrollable'>" +
"<div class='section_title'>{TITLE}</div>" +
"</div>";
for(var i = 0; i < 3; i++) {
shuffledItems = shuffledItemsTemplate.replace(/{TITLE}/g, slidesArray[i]["title"]);
$container.append(shuffledItems);
}
which results in the following HTML:
<div id="fullpage" class="sections">
<div class="section fp-scrollable">
<div class="section_title">1 title</div>
</div>
<div class="section fp-scrollable">
<div class="section_title">2 title</div>
</div>
<!-- etc -->
</div>
Simple enough.
Here's the fullpage configuration:
new fullpage('#fullpage', {
css3: true,
scrollingSpeed: 1000,
navigation: true,
slidesNavigation: true,
controlArrows: false,
scrollOverflow: true, // even though this is set to true, it's not working
scrollOverflowOptions: {
scrollbars: false,
},
});
My problem is that I cannot scroll inside any div that's scrollable and is inside <div class="section"></div>, even though scrollOverflow: true is set, and I added the files in the correct order in the HTML. Any idea what might cause this issue and how to solve it?
<script src="Scripts/Legacy/vendor/jquery.min.js"></script>
<script src="Scripts/Legacy/third-party/scrolloverflow.min.js"></script>
<script src="Scripts/Legacy/third-party/fullpage.js"></script>
You might need to use the method fullpage_api.reBuid() right after appending a section. Try it out.
That, or initialise fullPage.js after appending the contents.
In any case, fullPage.js won't be able to detect new sections appended dynamically, you would have to put some more work from your part to make it work. Namely, destroying fullPage.js and initialising it again with every section/slide you add/remove dynamically.

Simple Kendo DropDownList binding in window

I have a form with a DropDownList inside a Kendo window and I want to bind existing data to it. Examples for this abound and I've done it in other situations before, but this one (which seems like it should be really easy) is escaping me because I can't seem for the life of me to get the DropDownList to show the correct value. I figure I must be missing something really simple, but I haven't done Kendo in over a year, and looking at my previous work isn't helping me either.
Extremely simplified code:
<button onclick="OnButtonClick();">Click Me</button>
<div id="form-window"></div>
<script type="text/x-kendo-template" id="form-template">
<div class="form-group">
<label for="Url">URL</label>
<input name="Url" type="text" value="#= Url #" required="required" />
</div>
<div class="form-group">
<label for="HttpVerb">HTTP verb</label>
<input name="HttpVerb" data-bind="value:HttpVerb" data-source="httpVerbsDataSource" data-value-field="verb" data-text-field="verb" data-role="dropdownlist" />
</div>
</script>
<script type="text/javascript">
var formWindow = $("#form-window")
.kendoWindow({
title: "Form",
modal: true,
visible: false,
resizable: false,
scrollable: false,
width: 500,
actions: ["Close"],
open: function () {
kendo.init($("#form-window"));
}
}).data("kendoWindow");
var formTemplate = kendo.template($("#form-template").html());
var httpVerbsDataSource = new kendo.data.DataSource({
data: [
{ verb: "GET" },
{ verb: "POST" },
{ verb: "PUT" }
]
});
function OnButtonClick(e) {
var dataItem = {
Url: "abcdef",
HttpVerb: "POST"
};
var windowContent = formTemplate(dataItem);
formWindow.content(windowContent);
formWindow.center().open();
}
</script>
When I click the button, the window opens and the form text field is populated correctly, and the DropDownList has properly been bound to the data source, but the value in my data item is not selected.
JS Bin: https://jsbin.com/wariyorilo/edit?html,js,output
What am I missing? Thanks in advance.

data-bind not working in List View template within Grid detail template

I need help using a Kendo UI list view which lives within a grid row detail template.
here is something I have done so far.
<div id="grid">
</div>
<script type="text/x-kendo-template" id="gridDetailTemplate">
<div class='grid-edit'>
<div class='edit-list'></div>
</div>
</script>
<script type="text/x-kendo-template" id="editItemtemplate">
<div class='edit-Item'>
#if(Type=='string'){#
<ul><li><b>#:Name#</b></li><li><input class='inputString' value='#:DataVal()#'/></li></ul>
#}else if(Type=='number'){#
<ul><li><b>#:Name#</b></li><li><input class='inputNumber' data-role='numerictextbox' data-type='number' value='#:DataVal()#'/></li></ul>
#}else if(Type=='date'){#
<ul><li><b>#:Name#</b></li><li><input class='inputDate' data-role='datepicker' value='#:kendo.toString(DataVal(),'MM/dd/yyyy')#'/></li></ul>
#}else if(Type=='boolean'){Name #<input type='checkbox'/>
#}#
</div>
</script>
<script type="text/javascript">
$(document).ready(function () {
$.get("http://localhost:4916/DataAttribute", function (data, status) {
var selFields = new Object();
$.each(data, function (index, elem) {
selFields[elem.Name] = new Object();
selFields[elem.Name]["type"] = elem.Type;
});
$("#grid").kendoGrid({
dataSource: {
type: "json",
transport: {
read: { url: "http://localhost:4916/Deal",
dataType: "json"
}
},
schema: {
data: "Data", total: "Total",
model: {
fields: selFields
}
}
},
height: 430,
filterable: true,
sortable: true,
pageable: false,
detailTemplate: kendo.template($("#gridDetailTemplate").html()),
detailInit: detailInit,
columns: [{
field: "SecurityName",
title: "Security Name",
width: 250
},
{
field: "DateOfAcquisition",
title: "Date Of Acquisition",
width: 120,
format: "{0:MM/dd/yyyy}"
}, {
field: "Acres",
title: "Acres",
width: 120
}
]
});
});
});
function detailInit(e) {
$.get("http://localhost:4916/DataAttribute", function (data, status) {
var detailRow = e.detailRow;
detailRow.find(".edit-list").kendoListView({
dataSource: {
data: data,
schema: {
model: {
DataVal: function () {
switch (this.get("Type")) {
case "number"
}
if (e.data[this.get("Name")])
return e.data[this.get("Name")];
else
return '';
}
}
}
},
template: kendo.template($("#editItemtemplate").html())
});
});
}
</script>
My code gets dynamic field list and binds it to the data source for grid.
Then, in the detailInit event, I find the div within row detail and convert it into kendo UI list, for which the template have been created.
Now, when I use data-bind="value: DataVal()" ,it doesn't pick up the values of List data source. It works the way I have done i.e. value="#: DataVal() #". But, data-role does not convert the fields to specified types which are datepicker and numericinput in my case.
I believe that data-role not being used is caused due to same issue as data-bind not being read.
Can anyone help me out with this? Also, feel free to suggest any alternate ways and general code improvements. I am an ASP.NET developer and usually don't work on pure html and javascript.
PS: I would be happy to provide the context on what I am trying to achieve here if anyone is interested.
Thanks in advance.
If you can rig up a jsFiddle or jsBin example that would help debug the issue.
However, try removing the parenthesis:
data-bind="value: DataVal"
Kendo should detect that DataVal is a function and call it on its own.
I experienced a similar situation in a listview template. I created a JSFiddle to demonstrate:
http://jsfiddle.net/zacharydl/7L3SL/
Oddly, the solution is to wrap the contents of the template in a div. It looks like your template already has this, so YMMV.
<div id="example">
<div data-role="listview" data-template="template" data-bind="source: array"></div>
</div>
<script type="text/x-kendo-template" id="template">
<!--<div>-->
<div>method 1: #:field#</div>
<div>method 2: <span data-bind="text: field"></span></div>
<input data-role="datepicker" />
<!--</div>-->
</script>
var model = kendo.observable({
array: [
{ field: 'A'},
{ field: 'B'}
]
});
kendo.bind($('#example'), model);

Datatable with bootstrap modal window

I have two pages...both are having same table content...the only difference is in their content loading technique..
1) http://myraipur.com/SuprError/Test2.php
Here the datatable content is loaded by simple “Tr” and “Td”. Modal window is working properly.
2) http://myraipur.com/SuprError/Test1.php
Here the datatable content is loaded via deferred loading. The modal window is not working.
can you please help me!!
Just to add a method I feel that is straight forward that worked for me. ( Also my first Stackoverflow post! )
First used the Javascript Modal function provided by,
http://dotnetspeak.com/2013/05/creating-simple-please-wait-dialog-with-twitter-bootstrap
var loading;
loading = loading || (function () {
var pleaseWaitDiv = $('<div class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true"><div class="modal-dialog modal-sm"><div class="modal-content"><div class="modal-header"><button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button><h4 class="modal-title" id="mySmallModalLabel">Loading Data</h4></div><div class="modal-body"><div class="progress"><div class="progress-bar progress-bar-striped active" role="progressbar" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100" style="width: 100%"></div></div></div></div><!-- /.modal-content --></div><!-- /.modal-dialog -->');
return {
showPleaseWait: function() {
pleaseWaitDiv.modal();
},
hidePleaseWait: function () {
pleaseWaitDiv.modal('hide');
},
};
})();
And here is my Data table call
$(document).ready(function() {
$('#address')
.on( 'processing.dt', function ( e, settings, processing ) {
if (processing) {
$(document).ready(function() {
$('#address').click(loading.showPleaseWait());
});
} else {
$(document).ready(function() {
$('#address').click(loading.hidePleaseWait());
});
}
} )
.dataTable({
"Processing": false,
"sAjaxSource": "ajax/ajax_address_list.php",
"aoColumns": [
{ mData: 'add_cust' } ,
{ mData: 'add_main' },
{ mData: 'add_alias' }
],
"iDisplayLength": 50
});
} );
Hope this helps!
You need to run this code when your deferred is finished instead of document ready:
$("a[data-toggle=modal]").click(function (e) {
lv_target = $(this).attr('data-target');
lv_url = $(this).attr('href');
$(lv_target).load(lv_url);
});

Knockout Validation & Proper way to clear controls

I have the following code and it works fine, EXCEPT when you clear the property after you have inserted an item. The error shows up right away.
ko.validation.configure({
insertMessages: false,
decorateElement: true,
errorElementClass: 'error'
});
FirstName: ko.observable().extend({
required: true
}),
and I have add method in the knockout viewmodel
addItem: function () {
if (!viewModel.isValid()) {
viewModel.errors.showAllMessages();
return false;
} else {
//DO SOMETHING
this.SomeCollection.push(newInterviewee);
this.FirstName(null);
}
},
I have the following in the HTML:
<div>
<label>First Name</label>
<input data-bind="value: FirstName, validationElement: FirstName, valueUpdate: 'keyup'" class="input" type="text">
</div>
<div>
<div>
<input data-bind="click: addItem" class="button" type="button">
</div>
The problem is that after I call this.FirstName(null). The error shows up right away! I want the error to show up only when they press the button even after the property is cleared
Here is the solution that is provided by Steve Greatrex: https://github.com/Knockout-Contrib/Knockout-Validation/issues/210
We had the same issue on our project. We solved this by forcing isValid to true.
addItem: function () {
if (!viewModel.isValid()) {
viewModel.errors.showAllMessages();
return false;
} else {
//DO SOMETHING
this.SomeCollection.push(newInterviewee);
this.FirstName(null);
viewModel.isValid(true);
}
},
To be able to do this, you need to overwrite ko.validation's definition for the isValid computed as follows:
observable.isValid = ko.computed({
read: function() {
return observable.__valid__();
},
write: observable.__valid__
}
);

Resources