OctoberCMS Render Partial to MDB Datatable - datatable

I would like to update the MDB Datatable data in OctoberCMS partial with the latest data. Without the beforeUpdate function, it would retrieve the latest data but without the datatable. With the beforeUpdate function, it shows "cannot reinitialize datatable".
$.request('onFilter', {
data:{
'year':$("select[name='year']").val(),
},
update: {
'site/result': '#result'
},
beforeUpdate: function() {
if ( $.fn.DataTable.isDataTable('#result') ) {
$('#result').DataTable().destroy();
}
$('#resultTbl tbody').empty();
$('#resultTbl').DataTable({
"pageLength": 25,
"pagingType": "simple_numbers",
"scrollY": 450,
})
},
})

Here I solved my problem. Destroy the datatable beforeUpdate, and reinitialize during complete.
$.request('onFilter', {
data:{
'month':$("select[name='month']").val(),
'year':$("select[name='year']").val(),
'department':$("select[name='department']").val(),
'employeeName':$("input[name='employee-name']").val()
},
update: {
'site/result': '#result'
},
beforeUpdate: function() {
$("#resultTbl").dataTable().fnDestroy();
},
complete: function(){
$('#resultTbl').DataTable({
"pageLength": 25,
"pagingType": "simple_numbers",
"scrollY": 450,
})
},
})

Related

How can we access the datatable individual column searched value to controller(C# .net Mvc) while using the server side processing?

I have used datatable individual column searching .
below is my js code:
var BindDataTable = function (response) {
var oTable;
$("#example").DataTable({
initComplete: function () {
// Apply the search
this.api().columns().every(function () {
var that = this;
$('input', this.footer()).on('keyup change clear',
function () {
if (that.search() !== this.value) {
that.search(this.value).draw();
}
});
});
},
"searching": true,
// dom: '<"class">Blfrtip',
dom: "<'row mb-3'<'col-sm-12 col-md-2 col-lg-2'l><'col-sm-12 col-md-10 col-lg-10 datatableButtonsCon text-right'Bf>>" +
"<'row'<'col-sm-12 datatablesData'tr>>" +
"<'row mt-4'<'col-sm-12 col-md-4 col-lg-6 infoCon'i><'col-sm-12 col-md-8 col-lg-6 pagCon'p>>",
"bServerSide": true,
"sAjaxSource": "/AspNetStudents/GetStudents",
"fnServerData": function (sSource, aoData, fnCallback) {
$.ajax({
type: "POST",
data:aoData,
url: sSource,
success:fnCallback
})
},
"aoColumns": [
{ "mData": "Name" },
{ "mData": "RollNo" },
{ "mData": "CellNo" },
{ "mData": "JoiningDate" },
{ "mData": "ClassName" },
{ "mData": "TotalWithoutAdmission" },
{ "mData": "UserStatus" },
]
});
oTable = $('#example').DataTable();
oTable.columns(0).search("data");
oTable.draw();
I have also attached the backend C# code to access the individual datatable column value to controller.
How can we access the datatable individual column searched value to controller(C# .net Mvc) while using the server side processing?
just as an idea, I know it makes ajax request every time a draw method is called.In this case, the data can be serialized and sent,then the searched data can be accessed by performing a parse operation in the controller.
$.ajax({
type: "POST",
dataType: "json",
url: sSource,
data: function (data) {
data.filters = $(".filter").serialize();
},
success:fnCallback
})
// search
$(".filter").on("change", function (e) {
e.preventDefault();
table.draw();
});
...
// in controller
// parse request

JQuery : Datatable is not showing data properly after scrolling the table

I have an application wherein I want to show table as a card list layout i.e. the each record/row would be a separate card and 3 such cards should be displayed in a row.I also want an infinite scroll with server side rendering.
scenario:
total records are 105 and the length of the records is 30 but after scroll, it renders blank area and after 2nd/3rd draw the cards are displaying again.
Please find example below.
$(document).ready(function () {
$(document).on('preInit.dt', function (e, settings) {
let api = new $.fn.dataTable.Api(settings);
api.page.len(30);
});
var dtable = $('#paginatedTable').dataTable({
"processing": true,
"serverSide": true,
"searching": true,
"deferRender": false,
"order": [[0, "asc"]],
"ajax": {
"url": "/users/paginated/mysql"
},
"scrollY": '300px',
"scroller": {
" loadingIndicator": true,
},
"columns": [
{ "data": "id" },
{ "data": "name" },
{ "data": "salary" }
],
"createdRow": function (row, data, index) {
if (data.id) {
$('td', row).eq(0).addClass('text-left position-absolute l-0');
$('td', row).eq(1).addClass('text-right position-absolute r-0');
$('td', row).eq(1).addClass('alert-danger');
}
},
});
$('#search').on('keyup', function () {
dtable.fnFilter(this.value);
});
$("#sortingId").change(function () {
dtable.fnSort([0, $("#sortingId").val()]);
});
$("#sortingName").change(function () {
dtable.fnSort([1, $("#sortingName").val()]);
});
});
Screenshot:
Failure Scenario-above mentioned scenario
working scenario-if there is only one card in a row, scrolling is working fine

Grid remote data virtualization with custom transport.read method?

I would like to use the Kendo grid with remote data virtualization. I also need to have a custom method for the transport.read property.
My grid is configured like this:
$(document).ready(function () {
$("#grid").kendoGrid({
dataSource: {
serverPaging: true,
serverSorting: true,
pageSize: 100,
transport: {
read: function (options) {
// Get the template items, which could be products, collections, blogs or articles
getTemplateItems().then(function (data) {
options.success(data);
});
}
}
},
schema: {
total: function(response) {
return 2000;
}
},
height: 543,
scrollable: {
virtual: true
},
sortable: true,
columns: [
{ field: "title", title: "Title" }
]
});
});
function getTemplateItems() {
var deferred = $q.defer();
smartseoEntityMapping.getEntityInfo({ mappedEntityType: mappedEntityType.Product }).$promise.then(function (data) {
deferred.resolve(data);
});
return deferred.promise;
}
The problem is that the read method is only called once when the grid is initialized. It is not called when the scroll reaches the last item in the current visible set.
I suspect that the grid needs the total number of items but I cannot understand how to set the total number of items. Setting a method for the schema.total property does not work because the method is never called.
So I would like to ask you, is this scenario possible at all, to have the virtualization work with a custom transport.read method, which needs to be called every time to get the next page of data?
Why I am using a custom read? Well I cannot just set an url for the transport.read property because my remote call is made via an angularjs resource, involves setting authentication, etc...
schema is a property of a kendo datasource. It looks like you have it outside of the datasource.
Should be:
$("#grid").kendoGrid({
dataSource: {
serverPaging: true,
serverSorting: true,
pageSize: 100,
transport: {
read: function (options) {
// Get the template items, which could be products, collections, blogs or articles
getTemplateItems().then(function (data) {
options.success(data);
});
}
},
schema: {
total: function(response) {
return 2000;
}
}
},
height: 543,
scrollable: {
virtual: true
},
sortable: true,
columns: [
{ field: "title", title: "Title" }
]
});

jqGrid LoadOncomplete

Spec: JqGrid 1.11.2
Browser : Firefox 36.0.4
I have successfully be able to load json data on to a jQGrid via Ajax technique on click of a button.
Problem : I need some extra data "userdata" to be fetched along with the json-data to be loaded on to the page other then the jQGrid.
Grid Data:-
{
"total":"1",
"page":"1",
"records":"10",
"userdata":{"selZd":"23","selYd":"22","selXd":"21"},
"rows":[
{"id":"1","cell":["PDF","J2EEHandbook.pdf","/PDF Handbook.pdf"]}
]
}
Ajax-function : -
$(document).ready(function() {
$('#buttSerch').click(function() {
var newurl = 'Data.jsp?srchword='+
$('#srchTxt').val() +'&srchType='+gdsrctp;
$('#'+ gdivid).jqGrid().setGridParam(
{url : newurl }).trigger("reloadGrid");
//?? fetch userdata
});
});
Question : I need to fetch the data "userdata" in the Ajax function
How can this be achieved.
with regards
Karthik
The userdata can be accessed by usage getGridParam method with parameter "userData" (!! the case is important it should be userdata in the JSON data and "userData" in getGridParam method):
var userdata = $('#'+ gdivid).jqGrid("getGridParam", "userData");
Code for the Grid
colNames:['CATEGORY','PAGENO','CONTENTFILENAME','DATEOFCRTE','DATEOFINDEX','SIZEOF','UCODEDTLS','CONTENTEXTN','PATHOFCONTENT','CONTENT','DOCNUM','DOCWIGHT'],
colModel:[
{name:'CATEGORY',index:'true',width:'5',sortable:'true',align:'left',editable: true,formatter:iconColumnFormat },
{name:'PAGENO',index:'true',width:'3',sortable:'true',align:'left',editable: true, },
{name:'CONTENTFILENAME',index:'true',width:'25',sortable:'true',align:'left',editable: true, },
{name:'DATEOFCRTE',index:'true',width:'10',sortable:'true',align:'left',editable: true, },
{name:'DATEOFINDEX',index:'true',width:'10',sortable:'true',align:'left',editable: true, },
{name:'SIZEOF',index:'true',width:'8',sortable:'true',align:'left',editable: true, },
{name:'UCODEDTLS',index:'true',width:'8',sortable:'true',align:'left',editable: true, },
{name:'CONTENTEXTN',index:'true',width:'5',sortable:'true',align:'left',editable: true, },
{name:'PATHOFCONTENT',index:'true',width:'40',sortable:'true',align:'left',editable: true, },
{name:'CONTENT',index:'true',width:'15',sortable:'true',align:'left',editable: true,formatter:linkdialogColumnFormat },
{name:'DOCNUM',index:'true',width:'5',sortable:'true',align:'left',editable: true, },
{name:'DOCWIGHT',index:'true',width:'8',sortable:'true',align:'left',editable: true, }
],
url:'dummyData.jsp',
datatype:"json",
jsonReader:{root:'rows',page:'page',total:'total',records:'records', userdata:'userdata',cell:'cell',id:'id'},
loadComplete:'urlxdatafetch',
mtype:'GET',
hidegrid:false,
loadonce:true,
caption:"'Grid from Database -jsonstring'",
width:1200,
height:200,
rowNum:"10",
rowList:[10,50,100],
sortable:true,
sortorder:"desc",
shrinkToFit:true,
autowidth:true,
rownumbers:true,
footerrow:false,
viewsortcols:true,
viewrecords:true,
gridview:true,
autoencode:"true",
multiselect:true,
loadtext:"Data-Organized",
pager : "#pgerId",

Kendo Grid not calling correct DynamicLINQ method

My grid won't call my parameterized DataSourceResult methods. It just calls the parameterless one. I've studied this article till my eyes are falling out. What am I missing?
From my javascript controller:
$("#grid").kendoGrid({
dataSource: {
transport: {
read: function (options) {
userService.getGridUserList($.extend(options.data))
.success(function (result) { options.success(result); })
.error(function (result) { options.error(result); });
},
parameterMap: function(options, type) {
return kendo.stringify(options);
}
},
requestStart: function (e) {
},
requestEnd: function (e) {
},
schema: {
data: "data",
total: "total"
},
pageSize: 25,
serverPaging: true,
serverSorting: true,
serverFiltering: true
},
height: 600,
filterable: true,
sortable: true,
pageable: true,
columns: [
{ field: "firstName", title: "First Name" },
{ field: "lastName", title: "Last Name" },
{ field: "email", title: "email" }
]
});
From my C# WebAPI:
//**doesn't get called**
public DataSourceResult GetGridUserList(GetUserGridListInput input)
{
var q = repository.GetAll().OrderBy(t => t.Id);
return q.ToDataSourceResult(input.Take, input.Skip. input.Sort, input.Filter);
}
//**doesn't get called**
public DataSourceResult GetGridUserList(int take, int skip, IEnumerable<Sort> sort, Filter filter)
{
var q = repository.GetAll().OrderBy(t => t.Id);
return q.ToDataSourceResult(take, skip, sort, filter);
}
//**gets called every time**
public DataSourceResult GetGridUserList()
{
var q = repository.GetAll().OrderBy(t => t.Id);
return q.ToDataSourceResult(500, 0, null, null);
}
Turns out I was clobbering the grid parameters in my service call. What I needed to fix it, is to add {} as the first parameter:
userService.getGridUserList({}, $.extend(options.data))
The example uses a POST request, perhaps the grid requires that.
"I'm using a POST since MVC blocks unsecured GETS by default. That's
good since we're going to be needing a POST request structure coming
up shortly."

Resources