Changing default button with Icon in Jquery DataTable is not working - css

I am using JQUERY DataTable. In that I am trying to change default button text with Icon. But except copy and Print other button icon is not changing. I am using Font Awesome To change text with icon. I have added Font Awesome : CDN also But its not appearing for csv, excel, pdf Why so? Am i missing any JQUERY references
Font Awesome CDN
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css" />
To Change Text with Icon
initComplete: function () {
$('.buttons-copy').html('<i class="fa fa-copy" />')
$('.buttons-csv').html('<i class="fa fa-file-text-o" />')
$('.buttons-excel').html('<i class="fa fa-file-excel-o" />')
$('.buttons-pdf').html('<i class="fa fa-file-pdf-o" />')
$('.buttons-print').html('<i class="fa fa-print" />')
},
Complete JQuery DataTable
function LoadTableData() {
var params = {
PlantCode: $('#ddlPlant').val(), CostCenterCode: $("[id$='ddlCostCenter']").val(),
Status: $('input[name="Status"]:checked').val(), CompanyCode: $("[id$='ddlCompany']").val()
};
$.ajax({
url: 'UserService.asmx/Get_Data_Cost_Center_Master',
method: 'post',
data: JSON.stringify(params),
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function (data) {
$('#example').dataTable({
destroy: true,
data: data /*JSON.parse(data)*/,
columns: [
{
render: function (data, type, row, meta) {
return meta.row + meta.settings._iDisplayStart + 1;
}
},
{ 'data': 'Cost_Center', class: 'editable text' },
{ 'data': 'Plant', class: 'editable text' },
{ 'data': 'Status', class: 'editable text' }
],
dom: 'Bfrtip',
buttons: [
'copy', 'csv', 'excel', 'pdf', 'print'
],
initComplete: function () {
$('.buttons-copy').html('<i class="fa fa-copy" />')
$('.buttons-csv').html('<i class="fa fa-file-text-o" />')
$('.buttons-excel').html('<i class="fa fa-file-excel-o" />')
$('.buttons-pdf').html('<i class="fa fa-file-pdf-o" />')
$('.buttons-print').html('<i class="fa fa-print" />')
},
"searching": true,
"paging": true,
"info": true,
"language": {
"emptyTable": "No data available"
},
"fnRowCallback": function (nRow, aData, iDisplayIndex) {
$("td:first", nRow).html(iDisplayIndex + 1);
return nRow;
},
})
},
error: function (err) { // Added this event to capture the failed requests.
console.log(err.responseText);
}
});
};
Screenshot's
Where i am going Wrong? Kindly help me

Related

Asp.Net MVC jqgrid is not displaying my data

I am trying to fill a jqgrid. The grid is rendered but no data is displayed. I know my controller -- as called through a standard ajax function -- is working. It returns the data I'd expect.
How do I verify that jqgrid is returning the same data and what am I doing incorrectly that is not allowing the data to be dispayed?
jqgrid:
<script type="text/javascript">
jQuery(document).ready(function() {
$.ajaxSetup({ cache: false });
var rvtoken = $("input[name='__RequestVerificationToken']").val();
var ModuleId = #Dnn.ModuleContext.ModuleId;
var TabId = #Dnn.ModuleContext.TabId;
$('#grid').jqGrid({
url: '/DesktopModules/MVC/CW.GridTest/Item/getArtists2',
datatype: 'json',
mtype: 'POST',
contentType: 'application/json',
loadBeforeSend: function(jqXHR) {
jqXHR.setRequestHeader('ModuleId', ModuleId);
jqXHR.setRequestHeader( 'TabId', TabId);
jqXHR.setRequestHeader('RequestVerificationToken', rvtoken);
},
colNames: ['ArtistID', 'ArtistName', 'City'],
colModel: [
{ name: 'ArtistID', index: 'ArtistID', width: 80, align: 'left', editable: false },
{ name: 'Name', index: 'ArtistName', width: 120, align: 'left', editable: true },
{ name: 'Location', index: 'City',width: 60,align: 'left',editable: true}
],
loadError: function (jqXHR, textStatus, errorThrown) {
alert('HTTP status code: ' + jqXHR.status + '\n' +
'textStatus: ' + textStatus + '\n' +
'errorThrown: ' + errorThrown);
alert('HTTP message body (jqXHR.responseText): ' + '\n' + jqXHR.responseText);
},
loadOnce: true,
autoencode: true,
height: '100%',
rowNum: 10,
emptyrecords: 'No records',
sortname: 'ArtistID',
sortorder: 'desc',
viewrecords: true,
caption: 'Artists',
width: 300,
gridview: true,
jsonReader:
{
total: 'total',
page: 'page',
records: 'records',
root: 'rows',
repeatitems: false,
id: 'ArtistID'
}
});
jQuery("#grid").jqGrid('navGrid', '#pager', { edit: false, add: false, del: false });
});
</script>
<div>
<table id="grid"></table>
<div id="pager"></div>
</div>
Returned data from standard ajax:
{
"total":100,
"page":99,
"records":6,
"rows":"[
{\"ArtistID\":1,\"ArtistName\":\"Clayton Knight\",\"City\":\"Tigard\"},
{\"ArtistID\":2,\"ArtistName\":\"Corral Creek Bluegrass\",\"City\":\"Sherwood\"},
{\"ArtistID\":3,\"ArtistName\":\"Never Strangers Band\",\"City\":\"Portland\"},
{\"ArtistID\":5,\"ArtistName\":\"The Hillwilliams\",\"City\":\"Tigard\"},
{\"ArtistID\":7,\"ArtistName\":\"Bobo and the Bobbettes\",\"City\":\"Ellensburg\"},
{\"ArtistID\":27,\"ArtistName\":\"Bobo 5\",\"City\":\"Ellensburg\"}
]"
}
It was my controller. Not that it wasn't working but that it wasn't returning what I thought it should be. I was deserializing the data table for the "rows" element, and then deserializing the entire element again. So, the controller wasn't return a json string that jqgrid could actually work with.
It's all working now...
public String getArtists2()
{
using (var ac = new ArtistListingController())
{
ac.Gets();
ac.LoadDatatable();
DataView view = new DataView(ac.Datatable);
DataTable dt = view.ToTable(false, "ArtistID", "ArtistName", "City");
var jsonData = new
{
page=1,
total = 1, // (ac.RecordCount + rows - 1) / rows,
records = ac.RecordCount,
rows = dt //JsonConvert.SerializeObject(dt)
};
return JsonConvert.SerializeObject(jsonData);
}
}
Returning:
{
"page":1,
"total":1,
"records":6,
"rows":[
{
"ArtistID":1,
"ArtistName":"Clayton Knight",
"City":"Tigard"
},
{
"ArtistID":2,
"ArtistName":"Corral Creek Bluegrass",
"City":"Sherwood"
},
{
"ArtistID":3,
"ArtistName":"Never Strangers Band",
"City":"Portland"
},
{
"ArtistID":5,
"ArtistName":"The Hillwilliams",
"City":"Tigard"
},
{
"ArtistID":7,
"ArtistName":"Bobo and the Bobbettes",
"City":"Ellensburg"
},
{
"ArtistID":27,
"ArtistName":"Bobo 5",
"City":"Ellensburg"
}
]
}

Need to transform Razor code on ASPX code

So, I need help to make this code work as ASPX, can anyone help me?
I know it,s just a few parts to be changed, but i don't know how to do it...
Or if Any one know hot to achive the same result other way this would be very helpfull.
I already try do it myself but got no luck doing so.. =/
So, I need help to make this code work as ASPX, can anyone help me?
I know it,s just a few parts to be changed, but i don't know how to do it...
Or if Any one know hot to achive the same result other way this would be very helpfull.
I already try do it myself but got no luck doing so.. =/
#{
ViewBag.Title = "Employee List";
}
<a class="btn btn-success" style="margin-bottom:10px"
onclick="PopupForm('#Url.Action("AddOrEdit","Employee")')"><i class="fa fa-
plus"></i> Add New</a>
<table id="employeeTable" class="table table-striped table-bordered"
style="width:100%">
<thead>
<tr>
<th>Name</th>
<th>Position</th>
<th>Office</th>
<th>Age</th>
<th>Salary</th>
<th></th>
</tr>
</thead>
</table>
<link href="https://cdn.datatables.net/1.10.15/css/dataTables.bootstrap.min.css" rel="stylesheet" />
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
#section scripts{
<script src="//cdn.datatables.net/1.10.15/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.10.15/js/dataTables.bootstrap.min.js"></script>
<script>
var Popup, dataTable;
$(document).ready(function () {
dataTable = $("#employeeTable").DataTable({
"ajax": {
"url": "/Employee/GetData",
"type": "GET",
"datatype": "json"
},
"columns": [
{ "data": "Name" },
{ "data": "Position" },
{ "data": "Office" },
{ "data": "Age" },
{ "data": "Salary" },
{"data":"EmployeeID" , "render" : function (data) {
return "<a class='btn btn-default btn-sm' onclick=PopupForm('#Url.Action("AddOrEdit","Employee")/" + data + "')><i class='fa fa-pencil'></i> Edit</a><a class='btn btn-danger btn-sm' style='margin-left:5px' onclick=Delete("+data+")><i class='fa fa-trash'></i> Delete</a>";
},
"orderable": false,
"searchable":false,
"width":"150px"
}
],
"language": {
"emptyTable" : "No data found, Please click on <b>Add New</b> Button"
}
});
});
function PopupForm(url) {
var formDiv = $('<div/>');
$.get(url)
.done(function (response) {
formDiv.html(response);
Popup = formDiv.dialog({
autoOpen: true,
resizable: false,
title: 'Fill Employee Details',
height: 500,
width: 700,
close: function () {
Popup.dialog('destroy').remove();
}
});
});
}
function SubmitForm(form) {
$.validator.unobtrusive.parse(form);
if($(form).valid()){
$.ajax({
type : "POST",
url : form.action,
data : $(form).serialize(),
success : function (data) {
if(data.success)
{
Popup.dialog('close');
dataTable.ajax.reload();
$.notify(data.message,{
globalPosition :"top center",
className : "success"
})
}
}
});
}
return false;
}
function Delete(id) {
if(confirm('Are You Sure to Delete this Employee Record ?'))
{
$.ajax({
type: "POST",
url: '#Url.Action("Delete","Employee")/' + id,
success: function (data) {
if (data.success)
{
dataTable.ajax.reload();
$.notify(data.message, {
globalPosition: "top center",
className: "success"
})
}
}
});
}
}
</script>
}

Events not appearing when moving from an empty month

If I move from a month with events to a month without events and then back again, my events are not re-appearing. Moving between months with events is working fine. I have to refresh the page to get them to come back. Here is my code and I just cannot see anything wrong...
$("#datepicker").fullCalendar({
header: {
left: 'prev,next,cbRefresh',
center: 'title',
right: ''
},
height: 750,
firstDay: 1,
weekNumbers: true,
editable: false,
eventLimit: true,
displayEventTime: false,
dayClick: function(seldate,jsEvent,view) {
window.location.href="multiple?dt="+seldate.format();
},
eventClick: function(evt,jsEvent,view) {
if(evt.id) {
window.location.href="details?id="+evt.id+"&dt="+evt.start.format();
}
},
events: {
url: servicePath+"calendar.php",
type: 'GET',
data: function() {
var theDate=$("#datepicker").fullCalendar('getDate');
return {
t: 'load',
uid: uid,
mon: theDate.month()+1
}
},
error: function(){
displayError("Events error: " +item.ErrorMessage);
}
},
eventRender: function(evt,ele,view) {
$(ele).each(function(){
$(this).attr("data-num",evt.start.format("YYYY-MM-DD"));
$(this).attr("data-worked",evt.worked);
$(".fc-title",this).attr("title",evt.activity);
});
},
eventAfterAllRender: function(view) {
if(view.name=="month") {
for(cDay=view.start.clone(); cDay.isBefore(view.end); cDay.add(1,'day')) {
var ttl=0;
var dateNum=cDay.format('YYYY-MM-DD');
$(".fc-event-container").find('.fc-event[data-num="'+dateNum+'"]').each(function(){
var currentWorked=$(this).attr("data-worked");
if(currentWorked) {
ttl+=parseInt(currentWorked);
}
});
//display the total and relevant buttons
if(ttl>0) {
var footer=$('.fc-day[data-date="'+dateNum+'"]').find(".fc-cell-footer");
$(footer).append('<a title="Delete all" class="btn btn-xs" href="delete?dt='+dateNum+'">'+
'<span class="glyphicon glyphicon-trash"></span></a>'+
'<a title="Copy" class="btn btn-xs" href="copy?dt='+dateNum+'">'+
'<span class="glyphicon glyphicon-copy"></span></a>'+
'<a title="List" class="btn btn-xs" href="list?dt='+dateNum+'">'+
'<span class="glyphicon glyphicon-th-list"></span></a>');
$(footer).append('<span class="ttlHours">Hours: '+buildTime(ttl)+'</span>');
}
}
}
},
dayRender: function(date,cell) {
var theDate=moment(date).format("YYYY-MM-DD");
$(cell).css("vertical-align", "bottom");
$(cell).append('<div class="fc-cell-footer"></div>');
},
customButtons: {
cbRefresh: {
text: 'Refresh',
click: function() {
$("#datepicker").fullCalendar("destroy");
buildCalendar();
}
}
}
});
Have even tried stripping the code back to the very basics and still not working. I do know the 'events: data' is being fired every time as I have it set to email me (while testing).
$("#datepicker").fullCalendar({
header: {
left: 'prev,next,cbRefresh',
center: 'title',
right: ''
},
height: 750,
firstDay: 1,
weekNumbers: true,
editable: true,
eventLimit: true,
displayEventTime: false,
events: {
url: servicePath+"calendar.php",
type: 'GET',
data: function() {
var theDate=$("#datepicker").fullCalendar('getDate');
return {
t: 'load',
uid: uid,
mon: theDate.month()+1
}
},
error: function(){
displayError("Events error: " +item.ErrorMessage);
}
},
customButtons: {
cbRefresh: {
text: 'Refresh',
click: function() {
$("#datepicker").fullCalendar("destroy");
buildCalendar();
}
}
}
});
Sounds like the URL you provide is filtering on the events that the calendar should show. Try something simple as:
$("#calendar").fullCalendar({
events: {
url: 'getcalendar.php',
type: 'POST',
data: {
},
success : function(response){
console.log("Updated events: "+response.length);
}
}
});
Php:
<?php
$start = $_POST['start'];
$end = $_POST['end'];
$query = mysqli(X,"SELECT * FROM calendar startdate >= '$start' AND enddate <= '$end'");
echo json_encode(mysqli_fetch_array($query,MYSQLI_ASSOC));
?>

Adding/Removing eventSources FullCalendar

I'd like to be able to filter events based on adding and removing eventSources. I can't find a good example of this being done.
.fullCalendar( 'addEventSource', source )
.fullCalendar( 'removeEventSource', source )
I'd like to have check boxes that toggle the execution of those functions. I can't seem to get the functionality working though.
$( "#target" ).click(function() {
$('#calendar').fullCalendar( 'removeEventSource', 'Event1' );
});
Here is my full code:
$('#calendar').fullCalendar({
header: {
left: 'title',
center: 'prev,next',
right: 'month,agendaWeek,agendaDay,today'
},
eventLimit: {
'agenda': 4, // adjust to 6 only for agendaWeek/agendaDay
'default': true // give the default value to other views
},
eventSources: [
{
title: 'Event1',
url: "http://www.google.com/calendar/feeds/usa__en%40holiday.calendar.google.com/public/basic"
},
{
url: 'https://www.google.com/calendar/feeds/vineyardcincinnati.com_o6jncckm5ka55fpragnbp4mk9c%40group.calendar.google.com/public/basic'
},
{
url: "https://www.google.com/calendar/feeds/ht3jlfaac5lfd6263ulfh4tql8%40group.calendar.google.com/public/basic"
}
],
eventClick: function(event) {
// opens events in a popup window
window.open(event.url, 'gcalevent', 'width=700,height=600');
return false;
},
loading: function(bool) {
if (bool) {
$('#loading').show();
}else{
$('#loading').hide();
}
}
});
Here is the full code I used to get this functionality:
HTML:
<form id="#calendar_list">
<input class="checkbox" type="checkbox" checked>Event Group 1<br>
<input class="checkbox1" type="checkbox" checked>Event Group 2<br>
<input class="checkbox2" type="checkbox" checked>Event Group 3<br>
</form>
Javascript:
$(".checkbox").change(function() {
if(this.checked) {
$('#calendar').fullCalendar( 'addEventSource', 'https://www.google.com/calendar/feeds/vineyardcincinnati.com_o6jncckm5ka55fpragnbp4mk9c%40group.calendar.google.com/public/basic' );
}
else{
$('#calendar').fullCalendar( 'removeEventSource', 'https://www.google.com/calendar/feeds/vineyardcincinnati.com_o6jncckm5ka55fpragnbp4mk9c%40group.calendar.google.com/public/basic' );
}
});
Load FullCalendar : Use following given code to load FullCalendar. create a jquery function like LoadCalendar and put below code in this function and call this function on document.ready function in jquery.
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
locale: '#companyCulture',
defaultDate: Date.now(),
defaultView: 'month',
navLinks: true, // can click day/week names to navigate views
editable: false,
eventLimit: true, // allow "more" link when too many events
dayClick: function (date, allDay, jsEvent, view) {
//$("#lblDate").html('' + moment(date).format("MMMM DD,YYYY hh:mm") + '');
$("#lblDate").html('' + moment(date).format("MMMM DD,YYYY hh:mm A") + '');
$("#hdRDate").val(moment(date).format());
emptyEventDetails(date);
// $("#AddEventModel").modal();
},
eventClick: function (calEvent, jsEvent, view) {
$.ajax({
type: "GET",
async: false,
cache: false,
url: "#Url.Action("GetEventById", "Events")",
data: {
Eventid: calEvent.id
},
success: function (data) {
emptyEventDetails();
//$.each(data.data, function () {
// alert(this["Title"]);
// var color = 'orange';
// var Title = this["Title"];
// //addCalanderEvent(this["EventID"], this["EventDate"], Title, color);
//});
}
});
//$("#lblDate").html('' + calEvent.EventDate + '');
//$("#hdRDate").val(calEvent.EventDate);
//$("#AddEventModel").modal();
}
});
Add a Event: Use the below code to add a event in FullCalendar
var eventObject = {
title: title,
start: moment(start).format("MMMM DD,YYYY hh:mm A"),
end: moment(end).format("MMMM DD,YYYY hh:mm A"),
id: id,
color: colour
};
$('#calendar').fullCalendar('renderEvent', eventObject, true);
OR
$('#calendar').fullCalendar( 'addEventSource', newSource); //Add a new source
Remove all Events: I'm trying to remove all the event sources in the fullcalendar plugin. I'm currently using a combination of
$('#calendar').fullCalendar('removeEvents') //Hide all events
$('#calendar').fullCalendar('removeEventSource', $('.Source').val()) //remove eventSource from stored hidden input
OR
$('#Calendar').fullCalendar( 'removeEvents').fullCalendar('removeEventSources'); //Removes all event sources

Knockout asp.net - cannot read property of undefined

I'm really new to Knockout and have a question:
I try this example from the officail site.
So my html file is:
<head>
<script src="Scripts/jquery-2.1.1.min.js"></script>
<script src="Scripts/knockout-3.2.0.js"></script>
</head>
<body>
<div data-bind='simpleGrid: gridViewModel'> </div>
<button data-bind='click: addItem'>
Add item
</button>
<button data-bind='click: sortByName'>
Sort by name
</button>
<button data-bind='click: jumpToFirstPage, enable: gridViewModel.currentPageIndex'>
Jump to first page
</button>
<script src="FuseJS.js"></script>
</body>
</html>
and my js file is:
/// <reference path="Scripts/jquery-2.1.1.min.js" />
/// <reference path="Scripts/knockout-3.2.0.js" />
var initialData = [
{ name: "Well-Travelled Kitten", sales: 352, price: 75.95 },
{ name: "Speedy Coyote", sales: 89, price: 190.00 },
];
var PagedGridModel = function (items) {
this.items = ko.observableArray(items);
this.addItem = function () {
this.items.push({ name: "New item", sales: 0, price: 100 });
};
this.sortByName = function () {
this.items.sort(function (a, b) {
return a.name < b.name ? -1 : 1;
});
};
this.jumpToFirstPage = function () {
this.gridViewModel.currentPageIndex(0);
};
this.gridViewModel = new ko.simpleGrid.viewModel({
data: this.items,
columns: [
{ headerText: "Item Name", rowText: "name" },
{ headerText: "Sales Count", rowText: "sales" },
{ headerText: "Price", rowText: function (item) { return "$" + item.price.toFixed(2) } }
],
pageSize: 4
});
};
ko.applyBindings(new PagedGridModel(initialData));
What am I missing? I debug the code I saw this error
"UncauchType error: cannot read property 'viewModel' of undefined"
tnx
You are not using ko.applyBindings() anywhere.
ideally you need to do something like this.
ko.applyBindings(new PagedGridModel(initialData));

Resources