DataTable + JEditable + AutoComplete(BAssistance) + Server Side Processing - jquery-plugins

After almost struggling for a week I have been able to make DataTable + JEditable + AutoComplete(BAssistance) with server side processing using Json to work.
I thought it would be useful to somebody out there.
$(document).ready(function() {
$('#example tbody td').editable(
function(value, settings) {
processEventForTable(this, value);
return(value);
},
"height": "20px"
});
oTableexample = $('#example').dataTable({
"bInfo": true,
"bProcessing" : true,
"bServerSide" : true,
"sAjaxSource" : "GetPaginationData.aspx",
"sPaginationType": "full_numbers",
"bPaginate" : true,
"fnServerData": function ( sSource, aoData, fnCallback ) {
var data = {"name" : "kObjectId",
"value" : definitionId};
aoData.push(data);
data = { "name" : "ObjectName", "value" : "example" };
aoData.push(data);
data = { "name" : "InstanceId", "value" : instanceId };
aoData.push(data);
data = { "name" : "IsNewRequest", "value" : IsNewRowAdded};
IsNewRowAdded = 0;
aoData.push(data);
debugger;
$.ajax( {
"dataType": 'json',
"type": "Get",
"url": sSource,
"data": aoData,
"success": fnCallback
});
},
"fnDrawCallback" : function() {
debugger;
SetDataTableIDAndAttachJEditable("example");
$('#example tbody td').editable( function(value, settings)
{
var aPos = oTableexample.fnGetPosition( this );
processEventForTableNew(aPos[0], aPos[1], value, "example");
return(value);
}
);
}
});
$.editable.addInputType('autocomplete', {
element : $.editable.types.text.element,
plugin : function(settings, original) {
$('input', this).autocomplete(settings.autocomplete.url, {
dataType:'json',
parse : function(data) {
return $.map(data, function(item) {
return {
data : item,
value : item.Key,
result: item.value
}
})
},
formatItem: function(row, i, n) {
return row.value;
},
mustMatch: false,
focus: function(event, ui) {
$('#example tbody td[title]').val(ui.item.label);
return false;
}
});
}
});
$("#example tbody td > span[title]").editable(
function(value,settings){
return value;
},
{
type : "autocomplete",
tooltip : "Click to edit...",
autocomplete : {
url : "autocompleteeg.aspx"
}
}
);
});
This code works perfectly fine.
DataTables use Server Side Processing. And I am submitting the changes to JEditable to javascript function. From there on Submit I am submitting the entire change array to server.
This code has become too long can anybody help me refactor it.
If there is any better way to accomplish the same thing then I am waiting for it. :)

Yeah cool Dude !
Just a small syntax error in your code.
} , { // opening bracket missing
"height": "20px"
}
Thanks a lot

Related

DataTable can not pass parameters from Ajax to ASP.NET MVC controller

I have this problem when trying to pass a string parameter from DataTable with Ajax to an ASP.NET MVC controller: the parameter is not being sent.
I tried many forms of "data:" options. Please help me, I think I'm missing something important.
When (as a test) I initialize the parameter at the beginning of the controller with ttt="CO" everything goes fine!
$('#tblVacation').DataTable({
"ajax": {
"url": '/Vacation/LoadData2',
"contentType": "application/json;charset=utf-8",
"type": 'GET',
"dataType": 'JSON',
"data" : ' { ttt: "CO" }'
"dataSrc": "",
},
"columns": [
{ "data": "vacationId", width: "5%" },
{ "data": "operatorId", width: "3%" },
{ "data": "operator", width: "10%" },
{ "data": "type", width: "3%" },
]
});
And the controller is:
[HttpGet]
public ActionResult LoadData2(string ttt)
// ttt="CO";
{
List<Vacation> data = null;
try
{
data = DB.Vacations.Include(x => x.Operator).ToList();
var result = data.Select(x => new Vacation_VM
{
VacationId = x.VacationId,
OperatorId = x.OperatorId,
Vacation_doc = x.Vacation_doc,
Operator = x.Operator.Name,
Type = x.Type,
}).Where(m => m.Type == ttt);
return new JsonResult(result);
}
catch (Exception ex)
{
ViewBag.Message = ex.Message;
}
return new JsonResult(null);
}
I also tried with
var entity = {
ttt: "CO"
}
var dataToSend = JSON.stringify(entity);
and
"data": function () {
return dataToSend;
},
but it's still not working. I will need in the future to pass multiple parameters.
Thanks a lot, I will appreciate any advice.
Replace the ajax call part with the followings:
"ajax": {
type: 'GET',
url: '/Vacation/LoadData2',
data: { ttt: "CO" },
dataType: 'JSON',
async: true,
cache: false,
},

how to change data sorting in kendo ui donut chart series categoryField?

i'm mina.
I would like to specify the order of data in series categoryFiled.
categoryField has received a status value.
status has 0, 1, and 2 status values.
status 0 : disconnct
status 1 : connect
status 2 : running
Can I get the order of 2,1,0 using the sort option?
this is my code :
var toKorean = (function(){
var set = {
"RUNNING" : /*[[#{dashboard.Executing}]]*/,
"CONNECT" : /*[[#{dashboard.Connect}]]*/,
"DISCONNECT" : /*[[#{dashboard.Disconnect}]]*/,
};
return (function(status){
for(var i in set)
{
console.log(status);
if(i == status)
{
return set[i];
}
}
})
})();
function createChart(type) {
$( "#"+type ).kendoChart({
transitions: false,
renderAs: "canvas",
dataSource: {
transport: {
read: {
url: "dashboard/" + type +".json",
dataType: "json"
}
},
schema:{
data: function(response){
console.log(response);
for(i in response)
{
var status = response[i].status;
response[i].status = toKorean(status);
}
return response;
}
},
sort : {
field: "status",
},
},
seriesDefaults: {
type: "donut",
labels: {
visible: true,
background: "transparent"
},
overlay: null
},
seriesColors:["#fd5a21","#ffde43","#66ccff"],
series: [{
field: "count",
categoryField: "status",
padding: 0
}],
});
}

How to reload Fuelux Tree with new data

Here i'm trying Fuelux Tree used in Ace admin Template. I have used the same code they have used.
The script code used in ace admin template:
jQuery(function($) {
var tree_data = {};
var sampleData = initiateDemoData(tree_data); //see below
$('#tree1')
.ace_tree({
dataSource: sampleData['dataSource1'],
multiSelect: true,
cacheItems: true,
'open-icon': 'ace-icon tree-minus',
'close-icon': 'ace-icon tree-plus',
'selectable': true,
'selected-icon': 'ace-icon fa fa-check',
'unselected-icon': 'ace-icon fa fa-times',
loadingHTML: '<div class="tree-loading"><i class="ace-icon fa fa-refresh fa-spin blue"></i></div>'
});
function initiateDemoData(tree_data) {
tree_data = {
"2C27D744B956": {
"text": "2C27D744B956",
"children": {
"001B179F4400": {
"text": "9991100003333",
"type": "item"
},
"9991100003333": {
"text": "9991100003333",
"type": "item"
},
"2c27d744b956": {
"text": "9991100003333",
"type": "item"
},
"002170615A04": {
"text": "9991100003333",
"type": "item"
}
},
"type": "folder"
}
};
var dataSource1 = function(options, callback) {
var $data = null
if (!("text" in options) && !("type" in options)) {
$data = tree_data; //the root tree
callback({
data: $data
});
return;
} else if ("type" in options && options.type == "folder") {
if ("children" in options)
$data = options.children || {};
else
$data = {} //no data
}
if ($data != null) //this setTimeout is only for mimicking some random delay
setTimeout(function() {
callback({
data: $data
});
}, parseInt(Math.random() * 500) + 200);
//we have used static data here
//but you can retrieve your data dynamically from a server using ajax call
//checkout examples/treeview.html and examples/treeview.js for more info
}
return {
'dataSource1': dataSource1
}
}
});
Then on a button click i'm trying to refresh the tree, with new data from ajax Get request, But when i tried, an error comes in browser such as "Uncaught TypeError: Cannot read property 'apply' of undefined ".
Following is my ajax code:
$.ajax({
type : "GET",
url : "getDevices.htm?did=" + dID,
success : function(data) {
tree_data = data; //tree_data is the data used for the treeview
$('#tree1').tree('reload');
},
error : function(data) {
console.log("failure" + data);
}
});
Please suggest a method to resolve this issue.
Thanks in advance.

Is it possible for pagination last button reload in jquery datatable?

Is it possible for pagination last button reload in jquery datatable?
I have used jquery datable ,Now my record more than one lack's data.
So I have page initialize 1000 record load and then last pagination button click reload data 1000.
can give me any other idea...?
For your reference:
$("#tblExmaple").hide();
jQuery(document).ready(function ($) {
getRecords();
function getRecords() {
jQuery.support.cors = true;
$.ajax({
cache: false,
type: "GET",
url: "http://localhost:1111/TestSample/api/getRecords",
datatype: "json",
data: { Arg1: "Values1",Arg2: "Values2",Arg2: "Values3" },
statusCode: {
200: function (data) {
$.each(data, function (index, obj) {
var colRes1 = obj.Res1;
var colRes2 = obj.Res2;
var dataAdd = [colRes1, colRes2];
getData.push(dataAdd);
});
// Server Side Code
setTimeout(function () {
$('#tblExmaple').dataTable({
"sPaginationType": "full_numbers",
"sScrollXInner": "50%",
"sScrollyInner": "110%",
"aaData": getData,
"iDisplayLength": 8,
"sInfoEmpty": false,
"bLengthChange": false,
"aoColumns": [
{ "sTitle": "Column1" },
{ "sTitle": "Column2" }
];
})
}, 500);
setTimeout(function () {
$("#tblExmaple").show();
}, 500);
},
408: function (data) {
var response_Text = JSON.stringify(data, undefined, 50);
if (data.response_Text == undefined) {
window.location = "/Home/Index";
}
else {
timeoutClear();
}
}
}
});
}

Custom validation with ajax.....Here remote method is not working

I am using jquery.validate.js, in the code below both remote and regex works separately but when I try to integrate both then it is not working. Can anybody help me where I did wrong?
<head>
<script type="text/javascript">
$(document).ready(function(){
$("#clear").click(function(){
$("input[type=text], textarea").val("");
});
});
function submitForm() {
$.validator.addMethod("subTitleVal", function(value, element) {
return this.optional(element) || /^[A-Za-z\s\_,\.:;()''""]+$/.test(value);
}, "Enter Valid Name.");
var validator = $("#company").validate({
errorPlacement : function(error, element) {
offset = element.offset();
error.insertBefore(element)
error.addClass('message');
error.css('position', 'absolute');
error.css('left', offset.left + element.outerWidth());
},
rules : {
name : {
required : true,
subTitleVal : true,
remote: {
type: 'POST',
url: "${pageContext.request.contextPath}/company/getDuplicate",
data: {"name":name},
dataType : "json",
success:function(data){
/* response = ( data == true ) ? true : false; */
if (data.name == true)
{
message: {
name: 'The username is already in use!'
}
}
}
},
}
},
},
errorElement : "span",
wrapper : "span",
messages : {
name : {
required : "Name Is Required",
}
}
});
if(validator.form()){
$('form#company').submit();
}
};
</script>
</head>
<body>
<form:form commandname="company" action="${pageContext.request.contextPath}/company/create.action" method="post" modelAttribute="company" name="theform">
<label>Name:</label>
<form:input path="name" id="name"></form:input>
Add
</form:form>
</body>
please help. Thanks
replace your code with this
function submitForm() {
$.validator.addMethod("subTitleVal", function(value, element) {
return this.optional(element)
|| /^[A-Za-z\s\_,\.:;()''""]+$/.test(value);
}, "Enter Valid Name.");
var validator = $("#company").validate({
errorPlacement : function(error, element) {
offset = element.offset();
error.insertBefore(element)
error.addClass('message');
error.css('position', 'absolute');
error.css('left', offset.left + element.outerWidth());
},
rules : {
name : {
required : true,
subTitleVal : true,
remote : {
type : 'POST',
url : "${pageContext.request.contextPath}/company/getDuplicate",
data : {
name: function() { return $("#name").val(); }
}
}
}
},
errorElement : "span",
wrapper : "span",
messages : {
name : {
required : "Name Is Required",
remote : "Name Already Taken."
}
}
});
if (validator.form()) {
$('form#company').submit();
}
};
From the documentation
The response is evaluated as JSON and must be true for valid elements,
and can be any false, undefined or null for invalid elements, using
the default message; or a string, eg. "That name is already taken, try
peter123 instead" to display as the error message.
So your validation url must return an appropriate value
Try
function submitForm() {
$.validator.addMethod("subTitleVal", function(value, element) {
return this.optional(element)
|| /^[A-Za-z\s\_,\.:;()''""]+$/.test(value);
}, "Enter Valid Name.");
var validator = $("#company").validate({
errorPlacement : function(error, element) {
offset = element.offset();
error.insertBefore(element)
error.addClass('message');
error.css('position', 'absolute');
error.css('left', offset.left + element.outerWidth());
},
rules : {
name : {
required : true,
subTitleVal : true,
remote : {
type : 'POST',
url : "${pageContext.request.contextPath}/company/getDuplicate",
data : {
"name" : name
}
}
}
},
errorElement : "span",
wrapper : "span",
messages : {
name : {
required : "Name Is Required"
}
}
});
if (validator.form()) {
$('form#company').submit();
}
};
Your brackets are not closed properly. You have an extra },
Keep your code well-indented to avoid such minor mistakes in the future.
This should be your code instead:
function submitForm() {
$.validator.addMethod("subTitleVal", function (value, element) {
return this.optional(element) || /^[A-Za-z\s\_,\.:;()''""]+$/.test(value);
}, "Enter Valid Name.");
var validator = $("#company").validate({
errorPlacement: function (error, element) {
offset = element.offset();
error.insertBefore(element)
error.addClass('message');
error.css('position', 'absolute');
error.css('left', offset.left + element.outerWidth());
},
rules: {
name: {
required: true,
subTitleVal: true,
remote: {
type: 'POST',
url: "${pageContext.request.contextPath}/company/getDuplicate",
data: {
"name": name
},
dataType: "json",
success: function (data) {
/* response = ( data == true ) ? true : false; */
if (data.name == true) {
message: {
name: 'The username is already in use!'
}
}
}
},
}
},
errorElement: "span",
wrapper: "span",
messages: {
name: {
required: "Name Is Required",
}
}
});
if (validator.form()) {
$('form#company').submit();
}
};

Resources