update Jquery Jtable plugin depending on a selected row in another Table - c#

hello I have the following snippet of code.
Departments
<div>Users </div>
<div id="UserTableContainer"></div>
<script type="text/javascript">
var departmentChangeId = 1;
$(document).ready(function () {
$('#DepartmentTableContainer').jtable({
paging: true,
useBootstrap: true,
sorting: true,
selecting: true,
selectOnRowClick: true,
title: 'Departments',
actions: {
listAction: '/api/Department/GetDepartmentList',
createAction: '/api/Department/CreateDepartment',
updateAction: '/api/Department/EditDepartment',
deleteAction: '/api/Department/DeleteDepartment'
},
fields: {
ID: {
key: true,
list: false
},
TypeId: {
title: 'Department Type',
options: '/api/Department/GetDepartmentTypeList'
},
Label: {
title: 'Department'
},
},
//Register to selectionChanged event to hanlde events
selectionChanged: function () {
//Get all selected rows
var $selectedRows = $('#DepartmentTableContainer').jtable('selectedRows');
departmentChangeId = $selectedRows.data('record').ID;
//alert(departmentChangeId);
//
refresh();
}
}).jtable('load');
$('#UserTableContainer').jtable({
messages: ArabMessages, //Lozalize
paging: true,
useBootstrap: true,
sorting: true,
title: 'Employee',
actions: {
listAction: '/api/Users/GetEmployee?id=' + departmentChangeId,
updateAction: '/api/Users/EditEmployee'
},
fields: {
Id: {
key: true,
list: false
},
DepId: {
title: ' Department',
options: '/api/Department/GetDepartmentTypeList'
},
LastName: {
title: 'Name'
},
}
});
$('#UserTableContainer').jtable('load');
});
and these are the two version I use for the refresh function
first
function refresh() {
$('#UserTableContainer').jtable('reload');
}
the second
function refresh() {
$.post("/api/Users/GetEmployee", "id=" + departmentChangeId,
function (results) {
$('#UserTableContainer').jtable('reload');
}
, "json");
}
unfortunately both of them dont work
instead of when I use debugging mode I see that the /api/Users/GetEmployee is visited in both case

please try using below code in refresh function
$('#UserTableContainer').jtable('load');

Related

Remove conditions in DataTables SearchBuilder

$('#example').DataTable({
searchBuilder: {
depthLimit: 1,
conditions: {
string: {
'=': null
}
}
},
dom: 'Qfrtip'
});
In this scenario , '=' equals condition was removed for the string type data.
But when using popup SearchBuilder it's not working.
This is the way to do this. SearchBuilder
Here is the code
<script>
$(document).ready(function () {
$(document).ready(function () {
$('#example').DataTable({
language: {
searchBuilder: {
button: {
0: 'Filter',
1: 'Filter (one applied)',
_: 'Filter (%d)'
}
}
},
buttons: [
{
extend: 'searchBuilder',
config: {
depthLimit: 1,
conditions: {
string: {
'=': null,
'!=': null
},
num: {
'=': null,
'!=': null
},
},
}
}
],
dom: 'Bfrtip'
});
});
});
</script>
Here the language option was used to change the name of the button. and other customizations are inside the buttons braces. Replace the dom attributes like below to align the table properly.
dom: "<'row'<'col-sm-12 col-md-6'B><'col-sm-12 col-md-6'f>>" +
"<'row'<'col-sm-12'tr>>" +
"<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",

how to add NOTEqual To rule in jQuery.validation

I want to know how i can add jquery validation for not equal values in two input textbox. I have tried this Example but its not working for me.
Jquery Code:
$.validator.addMethod("notEqual", function (value, element, param) {
return this.optional(element) || value != param;
}, "cannot be same as oldpassword");
$("#frmAddEdit").validate({
rules: {
"txtoldpassword": { required: true },
"txtnpassword": { required: true, notEqual:"#txtoldpassword" },
},
messages: {
"txtoldpassword": { required: "old Password is required" },
"txtnpassword": { required: "New Password is required" },
},
submitHandler: function (form) {
ChangeUserPassword();
return false;
}
});
When i put alert on validation method param shows the same value (i.e. #txtoldpassword) and when i put like this notEqual: $("#txtoldpassword").val() param becomes ""(blank)
Please help me on this.
I just changed the way of passing value of textbox for notEqual and it worked for me.
JQuery Code :
$("#frmAddEdit").validate({
rules: {
"txtoldpassword": { required: true, noSpace: true },
"txtnpassword": {
required: true, noSpace: true, notEqual: function () { return $("#txtoldpassword").val() },
}
},
messages: {
"txtoldpassword": { required: "old Password is required" },
"txtnpassword": { required: "New Password is required" },
},
submitHandler: function (form) {
ChangeUserPassword();
return false;
}
});

How to Pass Parameters to SignalR Read Opeartion of KendoUI DataSource

I am using a Kendo UI dataSource to bind KendoUIScheduler through SignalR. How can I pass parameters to the read operation of the dataSource with SignalR bindings?
I am using the following code:
var hub = $.connection.schedulerHub;
var hubStart = $.connection.hub.start();
$('#scheduler').kendoScheduler({
mobile: true,
height: 600,
views: [
'day',
'week',
'month',
'agenda',
{ type: 'timeline', selected: true }
],
timezone: 'Etc/UTC',
dataSource: {
type: "signalr",
push: function (e) {
alert(e.type);
},
autoSync: true,
transport: {
signalr: {
promise: hubStart,
hub: hub,
server: {
read:"read",
update: "update",
destroy: "destroy",
create: "create"
},
client: {
read:"read",
update: "update",
destroy: "destroy",
create: "create"
}
}
},
schema: {
model: {
id: 'SchedulerID',
fields: {
SchedulerID: { type: 'number', from: 'SchedulerID' },
start: { type: 'date', from: 'Start' },
end: { type: 'date', from: 'End' },
startTimezone: { from: "StartTimezone" },
endTimezone: { from: "EndTimezone" },
Title: { from: 'Title' },
isAllDay: { type: 'boolean', from: 'IsAllDay' },
recurrenceId: { from: "RecurrenceId" },
recurrenceException: { from: "RecurrenceException" },
recurrenceRule: { from: "RecurrenceRule" },
Users: { nullable: true, from: 'Users' },
},
}
}
},
group: {
resources: ['Users'],
orientation: 'vertical'
},
resources: [
{
field: 'Users',
name: 'Users',
dataSource: Users,
multiple: false,
title: 'Users'
}
]
});
I realize this question is old, but I was trying to find this same answer and didn't find any clear solutions. I did find some hints in other threads that led me to a solution although I'm sure there are better ones (I wasn't able to figure out how to send the parameters separately - only as one object).
In your datasource, use the parameterMap function to put in whatever custom parameters you want. When binding to WCF (commented code) you can separate the parameters for the call but I couldn't get that to work with the SignalR implementation.
type: "signalr",
transport: {
parameterMap: function (data, type) {
switch (type) {
case "read":
{
// this works
var request = {};
var chkunsub = $('#chkunsubscribed').is(':checked');
request.unsubscribed = chkunsub;
request.oKendo = data;
return request;
// Does not work (separating parameters)
//return {
// unsubscribed: chkunsub,
// oKendo: data
//};
}
// Does not work either (separating parameters)
//return kendo.stringify({
// unsubscribed: chkunsub ? 1 : 0,
// oKendo: data
//});
}
},
Note that the "data" variable contains the filter, paging, grouping, etc. (I'm binding to a grid but I would think it's the same for scheduler).
Then on the server side in your hub, you just need to mirror the class structure like this (my CKendoGridOptions class has all of the properties from the API such as page, skip, filter, etc).
Public Class EventRequestData
Public Property unsubscribed As Boolean
Public Property oKendo As CKendoGridOptions
End Class
' This works
Public Function read(data As EventRequestData) As OrmedReturnData
Dim oReturn As New OrmedReturnData
If IsLoggingEnabled() Then
WriteToEventLog("Hub getevent_item called")
End If
Dim oToken As TokenHelper.TokenData = TokenHelper.ValidateToken(New Guid(Context.Request.Cookies("token").Value))
If oToken.TokenOK = False Then
oReturn.Success = False
oReturn.ErrorMessage = ERROR_INVALID_TOKEN
Else
Dim oData As New EventItems
oReturn = oData.Getevent_items(data.unsubscribed, data.oKendo)
End If
Return oReturn
End Function
I hope this helps someone else who is trying to pass parameters to a read function using Kendo in jQuery and SignalR.

Jtable only displays when stepping through debugger

Hi I am struggling to display my jtable. It only displays when I step through the javascript with the debugger.
$("body").on("click", "#tabRole", function () {
document.getElementById("1").className = "inactive";
document.getElementById("2").className = "active";
$('#Admin-details').load('../Admin/ADRoleAdmin');
jTableRoles();
});
This method loads ADRoleAdmin as a partial view into a div. Then jTableRoles() should load the jtable into a div (jTableRoles) inside ADRoleAdmin:
var jTableRoles = function () {
$(function () {
debugger;
$('#jTableRoles').jtable({
paging: true,
pageSize: 20,
sorting: true,
title: 'Roles',
onRowEdit: function (event, data) {
UpdateRoleDetails(data.records.RoleId, data.records.RoleName);
},
actions: {
listAction: '../Admin/GetRoles',
updateAction: 'dummy'
},
toolbar: {
items: [{
icon: '../Content/images/Misc/Add icon.png',
text: 'Create New',
click: function () {
UpdateRoleDetails(0, '');
}
}]
},
fields: {
Id: {
key: true,
list: false
},
Name: {
title: 'Role name',
},
Description: {
title: 'Role description',
sorting: false
}
}
});
$('#jTableRoles').jtable('load');
});
}
Please tell me what I am doing wrong or what I can do different to make it work.
Looping through the steps takes extra time.
It looks like the load of ADRoleAdmin is not finished on the moment the jTable is loaded.
Try to start the jtable after a certain timeout to check.
Preferably load the ADRoleAdmin an on it's postback load the jTable

Uncaught TypeError : cannot read property 'pager' of undefined In KendoGrid

Im trying to keep option "All" for showing all the data in grid by using following code.
but when the code reaches grid.pager.element its showing error as "pager" undefined.
at first when i click on search with group "TBU" there is no option for All.When i click again "All" appears as how many times i have clicked.
$.ajax({
type: "POST",
url: "Report_Services/Report.asmx/BindKendoAvailableList",
data: "{'groupId':" + $('#cboGroupName option:selected').val() + "}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (result) {
data = result.d;
$("#grid").kendoGrid({
dataSource: {
transport: {
read: function (options) {
options.success(data);
}
},
schema: {
type: "xml",
data: "/NewDataSet/myTable",
model: {
// configure the fields of the object
fields: {
AssetCode: "AssetCode/text()",
AssetName: "AssetName/text()"
AssetStatusName: "AssetStatusName/text()"
}
}
},
pageSize: 10
},
sortable: true,
filterable: true,
reorderable: true,
navigatable: true,
selectable: "multiple",
columnMenu: true,
resizable: true,
pageable: {
refresh: true,
pageSizes: true,
buttonCount: 8
},
columns:
[{
field: "AssetCode",
title: "Asset Id"
}, {
field: "AssetName",
title: "Asset Name"
},{
field: "AssetStatusName",
title: "Status"
}]
});
}
});
debugger;
var grid = $("#grid").data("kendoGrid");
var dropdown = grid.pager.element
.find(".k-pager-sizes [data-role=dropdownlist]")
.data("kendoDropDownList");
var item = {};
item[dropdown.options.dataTextField] = "All";
item[dropdown.options.dataValueField] = 1000000;
dropdown.dataSource.add(item);
dropdown.bind("change", function (e) {
if (this.text() == "All") {
grid.one("dataBound", function () {
setTimeout(function () {
dropdown.span.text("All");
});
});
}
});
In your case it sounds like the grid variable is undefined not the pager. Make sure that you execute this code after the Grid is actually initialized and also make sure the selector is right.

Categories