I m using datatable to load data from the database. there is a datetime column that I want to Manipulate. So basically I want to use moment-js and convert datetime into the user's locale time and etc.
I tried createdRow however that event is called after data has been inserted into the rows.
is there beforeCreatedRow row type event so that I can Manipulate data before inserting it into a row?
$("#ronin").DataTable({
"order": [
[0, "desc"]
],
ajax: {
url: "r1.php",
dataSrc: ''
},
colReorder: {
realtime: true
},
createdRow: function(row, data, dataIndex) {
console.log(data.datetime);
return data.datetime = '2222-22-22 11:11:11'//test
},
"aoColumns": [{
data: 'id'
},
{
data: 'seed'
},
{
data: 'useragent'
},
{
data: 'ip'
},
{
data: 'datetime'
}
]
});
here is the code.
thank you.
To manipulate the data before its shown, my preferred approach is to use columns. render. It's not immediately obvious from the doc, but you can also pass a function to render:
...
"columnDefs": [ {
"targets": 4,
"data": "datetime",
"render": function ( data, type, row, meta ) {
return data = '2222-22-22 11:11:11'//test;
}
...
You can actually do this in the column initialization. Here you go:
$("#ronin").DataTable({
"order": [
[0, "desc"]
],
ajax: {
url: "r1.php",
dataSrc: ''
},
colReorder: {
realtime: true
},
createdRow: function(row, data, dataIndex) {
console.log(data.datetime);
return data.datetime = '2222-22-22 11:11:11'//test
},
"aoColumns": [{
data: 'id'
},
{
data: 'seed'
},
{
data: 'useragent'
},
{
data: 'ip'
},
{
data: 'datetime',
render: function(data, type, row) {
if (type === "sort" || type === "type") {
return data;
}
return moment(data).format('YYYY-MM-DD h:mm:ss A');
}
}
]
});
Here is a working example with some sample data:
var dataSet = [{
"id" : "123591345",
"seed": "543694385672452",
"useragent": "Not sure what this is",
"ip": "199.99.919.1",
"datetime": "7/30/2021"
}];
$(document).ready(function() {
moment.suppressDeprecationWarnings = true; //suppresses deprecation notifications in console
$('#example').DataTable( {
data: dataSet,
columns: [
{ data: "id" },
{ data: "seed" },
{ data: "useragent" },
{ data: "ip" },
{ data: "datetime",
render: function(data, type, row) {
if (type === "sort" || type === "type") {
return data;
}
return moment(data).format('YYYY-MM-DD h:mm:ss A');
}
}
]
} );
} );
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/5.0.1/css/bootstrap.min.css"/>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.25/css/dataTables.bootstrap5.min.css"/>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/buttons/1.7.1/css/buttons.bootstrap5.min.css"/>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/datetime/1.1.0/css/dataTables.dateTime.min.css"/>
<script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/5.0.1/js/bootstrap.bundle.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/1.10.25/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/1.10.25/js/dataTables.bootstrap5.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/datetime/1.1.0/js/dataTables.dateTime.min.js"></script>
<script src="https://momentjs.com/downloads/moment.min.js"></script>
<table id="example" class="table table-bordered" cellspacing="0" width="100%">
<thead>
<tr>
<th>ID</th>
<th>Seed</th>
<th>Useragent</th>
<th>IP</th>
<th>DateTime</th>
</tr>
</thead>
</table>
Related
Data is not getting loaded in JqGrid from controller in ASP.NET Core.
I tried two ways, you can see two different methods in controller which I tried.
What am I doing wrong?
Index.cshtml
<link rel="stylesheet" href="/css/ui.jqgrid.css" />
<link rel="stylesheet" href="/css/jquery-ui.css" />
<script type="text/javascript" src="/js/grid.locale-en.js"></script>
<script type="text/javascript" src="/js/jquery.jqGrid.min.js"></script>
<table id="jqGrid"></table>
<div id="jqGridPager"></div>
#section scripts {
<script type="text/javascript">
$(document).ready(function () {
$("#jqGrid").jqGrid({
url:'#Url.Action("Index", "Maintenance")',
mtype: "POST",
datatype: "json",
colModel: [
{ label: 'Badge', name: 'Badge', key: true, width: 75 },
{ label: 'User ID', name: 'User', width: 150 },
{ label: 'EmailAddress', name: 'EmailAddress', width: 150 },
{ label: 'FULL_NAME_PREFERRED', name: 'FULL_NAME_PREFERRED', width: 150 },
{ label: 'Active', name: 'Active', width: 150 }
],
viewrecords: true,
width: 780,
height: 250,
rowNum: 20,
pager: "#jqGridPager"
});
});
</script>
}
MaintenanceController
Way 1
public IActionResult Index()
{
var lstMaintenanceModels = repos.GetUsers();
return View(lstMaintenanceModels);
}
Way 2
public JsonResult Index()
{
var lstMaintenanceModels = repos.GetUsers();
return Json(lstMaintenanceModels);
}
Starup.cs
services.AddControllers().AddNewtonsoftJson(options =>
{
// Use the default property (Pascal) casing
options.SerializerSettings.ContractResolver = new DefaultContractResolver();
});
Output what i am getting right now
Way 1
Way 2
You need to write all js code in #section Scripts{}, Because the key in the json returned by the controller is lowercase, and what you wrote here is uppercase, it cannot be received. So in page you need to wirte like this :
The page needs to receive the value of json type, so you need to use the second method, or return the model directly, the program will automatically serialize it to json.
Code
<link crossorigin="anonymous" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.css" integrity="sha512-aOG0c6nPNzGk+5zjwyJaoRUgCdOrfSDhmMID2u4+OIslr0GjpLKo7Xm0Ao3xmpM4T8AmIouRkqwj1nrdVsLKEQ==" rel="stylesheet"></link>
<link crossorigin="anonymous" href="https://cdnjs.cloudflare.com/ajax/libs/free-jqgrid/4.15.5/css/ui.jqgrid.min.css" integrity="sha512-xAIWSSbGucVRdutqUD0VLDowcMF/K8W87EbIoa9YUYB4bTyt/zeykyuu9Sjp0TPVdgrgGgBVCBowKv46wY5gDQ==" rel="stylesheet"></link>
<link crossorigin="anonymous" href="https://cdnjs.cloudflare.com/ajax/libs/free-jqgrid/4.15.5/plugins/css/ui.multiselect.min.css" integrity="sha512-UuhJihFIXhnP4QEzaNXfLmzY9W3xoeTDATm0buV4wb2qJKoikNn568f0zA5QmrX0sp6VZzqE6fffvsTYU34tGA==" rel="stylesheet"></link>
<table id="dataTable"></table>
<div id="pager"></div>
#section Scripts
{
<script crossorigin="anonymous" integrity="sha512-uto9mlQzrs59VwILcLiRYeLKPPbS/bT71da/OEBYEwcdNUk8jYIy+D176RYoop1Da+f9mvkYrmj5MCLZWEtQuA==" src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<script crossorigin="anonymous" integrity="sha512-xt9pysburfYgFvYEtlhPDo8qBEPsupsDvWB8+iwspD+oQTvAdDEpA1aIKcH6zuABU528YitH6jtP0cAe5GrwKA==" src="https://cdnjs.cloudflare.com/ajax/libs/free-jqgrid/4.15.5/jquery.jqgrid.min.js"></script>
<script>
jQuery("#dataTable").jqGrid({
url:'#Url.Action("GetUsers", "Home")',
datatype: "json",
mtype: 'POST',
//here name must be
colModel: [
{ label: 'Badge', name: 'badge', key: true, width: 75 },
{ label: 'User ID', name: 'user', width: 150 },
{ label: 'EmailAddress', name: 'emailAddress', width: 150 },
{ label: 'FULL_NAME_PREFERRED', name: 'fulL_NAME_PREFERRED', width: 150 },
{ label: 'Active', name: 'active', width: 150 }
],
loadonce: true,
width: 780,
height: 250,
rowNum: 20,
pager: "#pager"
});
</script>
}
If the parameter datatype is 'json', jqGrid expects the following default format for JSON data
{
"total": "xxx",
"page": "yyy",
"records": "zzz",
"rows" : [
{"id" :"1", "cell" :["cell11", "cell12", "cell13"]},
{"id" :"2", "cell":["cell21", "cell22", "cell23"]},
]
}
You can read about this there^
http://www.trirand.com/jqgridwiki/doku.php?id=wiki:retrieving_data
Try this:
return Json(new { rows = repos.GetUsers() } );
I have a table:
<b-table striped hover :items="coursesArray" :fields="fields"></b-table>
The data comes from
coursesArray: [
{
id: "1",
name: "foo",
teacherEmails: [{ 0: "sample1" }, { 1: "sample2" }, { 2: "sample3" }],
teacherIds: ["A1", "A2", "A3"],
},
],
And fields are:
fields: [
{ key: "id", label: "Course ID" },
{ key: "name", label: "Course Name" },
{
key: "teacherEmails",
label: "Teacher Email",
formatter: "teacherEmailTCellFormat",
},
{ key: "teacherIds", label: "Teacher ID" },
],
And this is how it's rendered without the formatter.
So, I added a custom formatter in fields to remove the brackets and curly braces.
The first problem I'm having is that looping over the value to return all the items in teacherEmails does not work.
teacherEmailTCellFormat(value) {
console.log(value)
value.forEach(item => {
return each[0]
}
}
The second problem, that I don't understand why it's happening, is that if I log the value passed to the formatter, it's clear the formatter function is called twice.
Any help or clearance will be appreciated.
You need to return an array, you can do this using Array#map:
new Vue({
el:"#app",
data: () => ({
fields: [
{ key: "id", label: "Course ID" },
{ key: "name", label: "Course Name" },
{ key: "teacherEmails", label: "Teacher Email", formatter: "teacherEmailTCellFormat" },
{ key: "teacherIds", label: "Teacher ID" },
],
coursesArray: [
{
id: "1",
name: "foo",
teacherEmails: [{ 0: "sample1" }, { 1: "sample2" }, { 2: "sample3" }],
teacherIds: ["A1", "A2", "A3"],
}
]
}),
methods: {
teacherEmailTCellFormat(value) {
return value.map((item, i) => item[i]);
}
}
});
<link type="text/css" rel="stylesheet" href="https://unpkg.com/bootstrap/dist/css/bootstrap.min.css"/>
<link type="text/css" rel="stylesheet" href="https://unpkg.com/bootstrap-vue#latest/dist/bootstrap-vue.css"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.16/vue.min.js"></script>
<script src="https://unpkg.com/babel-polyfill#latest/dist/polyfill.min.js"></script>
<script src="https://unpkg.com/bootstrap-vue#latest/dist/bootstrap-vue.js"></script>
<div id="app">
<b-table striped hover :items="coursesArray" :fields="fields"></b-table>
</div>
Note: I assumed the key represents the index of the item in the array, but you can change the mapping as you want. The main issue was returning the array.
In my vuejs project how to use google data-table chart? Google data-table chart link given below:
https://developers.google.com/chart/interactive/docs/gallery/table
I can implement this chart in normal javascript code. But how to use in vuejs code.
You can use your own component. Here I have made one simple example.
Vue.component('google-data-table', {
template: `<div id='app' ref="table_div"></div>`,
props: {
columns: {
type: Array,
required: true
},
tableData: {
type: Array,
required: true
}
},
mounted() {
google.charts.load('current', {
'packages': ['table']
});
google.charts.setOnLoadCallback(this.drawTable);
},
methods: {
drawTable: function() {
var data = new google.visualization.DataTable();
this.columns.forEach(element => {
data.addColumn(element.type, element.title);
});
data.addRows(this.tableData);
var table = new google.visualization.Table(this.$refs.table_div);
table.draw(data, {
showRowNumber: true,
width: '100%',
height: '100%'
});
}
}
});
new Vue({
el: '#app',
data: {
columns: [{
type: 'string',
title: 'Name'
},
{
type: 'number',
title: 'Salary'
},
{
type: 'boolean',
title: 'Full Time Employee'
}
],
tableData: [
['Mike', {
v: 10000,
f: '$10,000'
}, true],
['Jim', {
v: 8000,
f: '$8,000'
}, false],
['Alice', {
v: 12500,
f: '$12,500'
}, true],
['Bob', {
v: 7000,
f: '$7,000'
}, true]
]
}
});
<html>
<head>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
</head>
<body>
<div id="app">
<google-data-table :columns='columns' :table-data='tableData' />
</div>
</body>
</html>
I am trying to use Datatable and I have an issue with Datatable populating data in my .net core project.When the page is loaded, DataTable records are empty.According to the picture below:
Controller:
public IActionResult ShowCategory()
{
return View();
}
public IActionResult CategoryList()
{
try
{
var draw = HttpContext.Request.Form["draw"].FirstOrDefault();
// Skiping number of Rows count
var start = Request.Form["start"].FirstOrDefault();
// Paging Length 10,20
var length = Request.Form["length"].FirstOrDefault();
// Sort Column Name
var sortColumn = Request.Form["columns[" + Request.Form["order[0][column]"].FirstOrDefault() + "][name]"].FirstOrDefault();
// Sort Column Direction ( asc ,desc)
var sortColumnDirection = Request.Form["order[0][dir]"].FirstOrDefault();
// Search Value from (Search box)
var searchValue = Request.Form["search[value]"].FirstOrDefault()
var data = _categoryRepository.GetCategories();
return Json(new { draw = 1, recordsFiltered = 4, recordsTotal = 4, data = data });
}
catch(Exception ex)
{
throw;
}
}
Due to a problem with the code, I have now passed the draw and ... to View as a hardcode.
GetCategories() method:
public List<CategoryViewModel> GetCategories()
{
var query = _CategoryRepo.GetAll();
var q = query.Select(s => new CategoryViewModel
{
Id = s.Id,
CaregoryParentId = s.CaregoryParentId,
Priority = s.Priority,
Title = s.Title
}).ToList();
return q;
}
view:
#{
Layout = null;
}
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<link href="~/css/admin/bootstrap.min.css" rel="stylesheet" />
<link href="https://cdn.datatables.net/1.10.15/css/dataTables.bootstrap.min.css" rel="stylesheet" />
<link href="https://cdn.datatables.net/responsive/2.1.1/css/responsive.bootstrap.min.css" rel="stylesheet" />
<script src="https://cdn.datatables.net/1.10.15/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.10.15/js/dataTables.bootstrap4.min.js "></script>
<div class="container">
<br />
<div style="width:90%; margin:0 auto;">
<table id="example" class="table table-striped table-bordered dt-responsive nowrap" width="100%" cellspacing="0">
<thead>
<tr>
<th>Id</th>
<th>Title</th>
<th>CaregoryParentId</th>
<th>Priority</th>
<th>Edit</th>
<th>Delete</th>
</tr>
</thead>
</table>
</div>
</div>
<script>
$(document).ready(function ()
{
$("#example").DataTable({
"processing": true, // for show progress bar
"serverSide": true, // for process server side
"filter": true, // this is for disable filter (search box)
"orderMulti": false, // for disable multiple column at once
"ajax": {
"url": "/Admin/Category/CategoryList",
"type": "POST",
"datatype": "json"
//"success": function (data) {
// alert(JSON.stringify(data));
//}
},
"columnDefs":
[{
"targets": [0],
"visible": false,
"searchable": false
}],
{ "data": "Id", "name": "Id", "autoWidth": true },
{ "data": "Title", "name": "Title", "autoWidth": true },
{ "data": "CaregoryParentId", "name": "CaregoryParentId", "autoWidth": true },
{ "data": "Priority", "name": "Priority", "autoWidth": true },
{
"render": function (data, type, full, meta)
{ return '<a class="btn btn-info" href="/DemoGrid/Edit/' + full.CustomerID + '">Edit</a>'; }
},
{
data: null, render: function (data, type, row)
{
return "<a href='#' class='btn btn-danger' onclick=DeleteData('" + row.CustomerID + "'); >Delete</a>";
}
},
]
});
});
function DeleteData(CustomerID)
{
if (confirm("Are you sure you want to delete ...?"))
{
Delete(CustomerID);
}
else
{
return false;
}
}
function Delete(CustomerID)
{
var url = '#Url.Content("~/")' + "DemoGrid/Delete";
$.post(url, { ID: CustomerID }, function (data)
{
if (data)
{
oTable = $('#example').DataTable();
oTable.draw();
}
else
{
alert("Something Went Wrong!");
}
});
}
</script>
when I debug, I receive data in Ajax success function, but it is not shown in the table.
can anybody help me?
Thanks a lot
when I debug, I receive data in Ajax success function, but it is not
shown in the table.
From the result above we can see, server return serializes JSON with camel case names by default.
Id => id
Title => title
CaregoryParentId => caregoryParentId
Priority => priority
But in your script, "data" is set as "Id".
Solution
Use the codes below to avoid camel case names by default.
services.AddControllersWithViews().AddJsonOptions(opts => opts.JsonSerializerOptions.PropertyNamingPolicy = null);
Codes of JS
$(document).ready(function ()
{
$("#example").DataTable({
"processing": true, // for show progress bar
"serverSide": true, // for process server side
"filter": true, // this is for disable filter (search box)
"orderMulti": false, // for disable multiple column at once
"ajax": {
"url": "/Admin/Category/CategoryList",
"type": "POST",
"datatype": "json",
//"success": function (data) {
// alert(JSON.stringify(data));
//}
},
"columnDefs":
[{
"targets": [0],
"visible": false,
"searchable": false
}],
"columns": [
{ "data": "Id", "name": "Id", "autoWidth": true },
{ "data": "Title", "name": "Title", "autoWidth": true },
{ "data": "CaregoryParentId", "name": "CaregoryParentId", "autoWidth": true },
{ "data": "Priority", "name": "Priority", "autoWidth": true },
{
"render": function (data, type, full, meta) { return '<a class="btn btn-info" href="/DemoGrid/Edit/' + full.CustomerID + '">Edit</a>'; }
},
{
data: null, render: function (data, type, row) {
return "<a href='#' class='btn btn-danger' onclick=DeleteData('" + row.CustomerID + "'); >Delete</a>";
}
}
]
});
});
Test of result
My snippets below shows a datatables example that has 3 rows, I have added an extra column in column definition "action" and I m setting its display/data via default content and render functions respectively.
every time I try to build an JSON data containing the column "action" val i fail. I added the cell click listener (disabled in this action) just to make sure that the data is stored in the API data collection and it is indeed, yet it fails to show up after building the values.
if you click "build vals" you will see how the "action" data is not included in JSON. if you click "Mark for delete" and then "build vals" the "action" data will show up.
any idea how to make it work?
var tablenest = $('#RegSrc').DataTable({
select: true,
"bPaginate": false,
"bFilter": false,
responsive: true,
deferRender: true,
"processing": true,
"serverSide": false,
bAutoWidth: true,
data: [{
"RecID": 2383,
"PtFilenum": 15090248,
"PrtFilenum": 13090701,
"Fullname": "Salem",
"PrtStatus": 1
}, {
"RecID": 2384,
"PtFilenum": 15090248,
"PrtFilenum": 15120996,
"Fullname": "Tony",
"PrtStatus": 1
}, {
"RecID": 2385,
"PtFilenum": 15090248,
"PrtFilenum": 170227111,
"Fullname": "Jorge",
"PrtStatus": 1
}],
order: [2, 'asc'],
keys: {
columns: ':not(:first-child)',
keys: [9]
},
columns: [
{ // Checkbox select column
data: null,
defaultContent: '',
className: 'select-checkbox',
orderable: false,
"width": "1%"
},
{
"width": "50%",
data: "RecID",
"visible": false
},
{
"width": "50%",
data: "PtFilenum",
"visible": false
},
{
"width": "10%",
data: "PrtFilenum"
},
{
"width": "40%",
data: "Fullname"
},
{
"width": "10%",
data: "PrtStatus",
render: function(data, type, row) {
if (type === 'display') {
if (data == 1) {
return 'Partners';
} else {
return 'Not Partners';
}
}
return data;
},
className: "dt-body-center"
},
{
"width": "10%",
data: 'action',
defaultContent: 'update',
orderable: false,
className: "dt-body-center",
"visible": true,
render: function(data, type, row) {
if (data == null) {
return 'update';
} else {
return data;
}
}
},
],
});
/* $('#RegSrc tbody').on('click', 'td', function () {
console.log(tablenest.cell(this).data());
});*/
$("#btn1").click(function() {
tablenest.rows({
selected: true
}).every(function(rowIdx, tableLoop, rowLoop) {
tablenest.row(this).cell(rowIdx, 6).data('delete').draw()
var row = tablenest.row(this).node();
$(row).css('color', 'red').animate({
color: 'black'
});
});
return false;
})
$("#btn2").click(function() {
var tbldta = $.map(tablenest.rows().data(), function(d, i) {
var myObject = new Object();
myObject = {
action: d.action,
RecID: d.RecID,
PrtStatus: d.PrtStatus,
ptfilenum: d.PtFilenum,
PrtFilenum: d.PrtFilenum
}
return myObject
});
var DtaObj = {}
DtaObj.Data = tbldta
console.log(JSON.stringify(DtaObj))
return false;
})
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://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 type="text/javascript" charset="utf-8" src="https://cdn.datatables.net/v/dt/jqc-1.12.4/moment-2.18.1/dt-1.10.15/b-1.3.1/se-1.2.2/datatables.min.js"></script>
<button id="btn2" class="btn btn-primary">build vals</button>
<button id="btn1" class="btn btn-primary">Mark For Delete</button>
<table id="RegSrc" class="table table-bordered table-striped table-condensed mb-none display responsive nowrap" cellspacing="0" width="100%">
<thead>
<tr>
<th>click here to select</th>
<th><b>RecID</b></th>
<th><b>Patient File Number</b></th>
<th><b>Partner File Number</b></th>
<th><b>Patient Name</b></th>
<th><b>Status</b></th>
<th><b>action</b></th>
</tr>
</thead>
<tbody>
</tbody>
</table>
Include "action":"update" to your data source in constructor.
columns.defaultContent is static and therefore cannot possibly access
the data.
Also you can remove render from "action" column.
var tablenest = $('#RegSrc').DataTable({
select: true,
"bPaginate": false,
"bFilter": false,
responsive: true,
deferRender: true,
"processing": true,
"serverSide": false,
bAutoWidth: true,
data: [{
"RecID": 2383,
"PtFilenum": 15090248,
"PrtFilenum": 13090701,
"Fullname": "Salem",
"PrtStatus": 1,
"action": "update"
}, {
"RecID": 2384,
"PtFilenum": 15090248,
"PrtFilenum": 15120996,
"Fullname": "Tony",
"PrtStatus": 1,
"action": "update"
}, {
"RecID": 2385,
"PtFilenum": 15090248,
"PrtFilenum": 170227111,
"Fullname": "Jorge",
"PrtStatus": 1,
"action": "update"
}],
order: [2, 'asc'],
keys: {
columns: ':not(:first-child)',
keys: [9]
},
columns: [
{ // Checkbox select column
data: null,
defaultContent: '',
className: 'select-checkbox',
orderable: false,
"width": "1%"
},
{
"width": "50%",
data: "RecID",
"visible": false
},
{
"width": "50%",
data: "PtFilenum",
"visible": false
},
{
"width": "10%",
data: "PrtFilenum"
},
{
"width": "40%",
data: "Fullname"
},
{
"width": "10%",
data: "PrtStatus",
render: function(data, type, row) {
if (type === 'display') {
if (data == 1) {
return 'Partners';
} else {
return 'Not Partners';
}
}
return data;
},
className: "dt-body-center"
},
{
"width": "10%",
data: 'action',
orderable: false,
className: "dt-body-center",
"visible": true
},
],
});
/* $('#RegSrc tbody').on('click', 'td', function () {
console.log(tablenest.cell(this).data());
});*/
$("#btn1").click(function() {
tablenest.rows({
selected: true
}).every(function(rowIdx, tableLoop, rowLoop) {
tablenest.row(this).cell(rowIdx, 6).data('delete').draw()
var row = tablenest.row(this).node();
$(row).css('color', 'red').animate({
color: 'black'
});
});
return false;
})
$("#btn2").click(function() {
var tbldta = $.map(tablenest.rows().data(), function(d, i) {
var myObject = new Object();
console.log(d);
myObject = {
action: d.action,
RecID: d.RecID,
PrtStatus: d.PrtStatus,
ptfilenum: d.PtFilenum,
PrtFilenum: d.PrtFilenum
}
return myObject
});
var DtaObj = {}
DtaObj.Data = tbldta
console.log(JSON.stringify(DtaObj))
return false;
})
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://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 type="text/javascript" charset="utf-8" src="https://cdn.datatables.net/v/dt/jqc-1.12.4/moment-2.18.1/dt-1.10.15/b-1.3.1/se-1.2.2/datatables.min.js"></script>
<button id="btn2" class="btn btn-primary">build vals</button>
<button id="btn1" class="btn btn-primary">Mark For Delete</button>
<table id="RegSrc" class="table table-bordered table-striped table-condensed mb-none display responsive nowrap" cellspacing="0" width="100%">
<thead>
<tr>
<th>click here to select</th>
<th><b>RecID</b></th>
<th><b>Patient File Number</b></th>
<th><b>Partner File Number</b></th>
<th><b>Patient Name</b></th>
<th><b>Status</b></th>
<th><b>action</b></th>
</tr>
</thead>
<tbody>
</tbody>
</table>