Implement Datatables responsive details display with Ajax data - datatables

I want to implement Datatable's responsive details with Bootstrap modal but it doesn't work for me. The first thing I noticed is that the "plus-sign" does not appear on the first column of my table. I'm not sure if this is because I'm using ajax data and need additional parameters that the example doesn't show or because I've added an auto number as my first column.
Here is the table HTML:
<table id="users" class="table table-striped table-bordered nowrap" data-conf="#Model.ExtraVM.DialogMsg" data-title="#Model.ExtraVM.DialogTitle" data-btnok="#Model.ExtraVM.Button1" data-btncancel="#Model.ExtraVM.Button2">
<thead>
<tr>
<th>#Model.HeadingVM.Col1</th>
<th>#Model.HeadingVM.Col2</th>
<th>#Model.HeadingVM.Col3</th>
<th>#Model.HeadingVM.Col4</th>
<th>#Model.HeadingVM.Col5</th>
</tr>
</thead>
<tbody></tbody>
</table>
Here is the jquery code:
<script>
$(document).ready(function () {
var t = $("#users").DataTable({
responsive: {
details: {
display: $.fn.dataTable.Responsive.display.modal({
header: function (row) {
var data = row.data();
return 'Details for ' + data[0] + ' ' + data[1];
}
}),
renderer: $.fn.dataTable.Responsive.renderer.tableAll({
tableClass: 'table'
})
}
},
columnDefs: [{
"searchable": false,
"orderable": false,
"targets": 0
}],
order: [[1, 'asc']],
ajax: {
url: "/api/users",
dataSrc: ""
},
columns: [
{
data: "id"
},
{
data: "firstName"
},
{
data: "lastName"
},
{
data: "userName"
},
{
data: "id",
render: function (data) {
return "<a href='#'><i class='fa fa-eye' data-id='" + data + "' data-toggle='modal' data-target='#dataPopup'></i></a> | <a href='#'><i class='fa fa-pencil js-edit' data-id='" + data + "'></i></a> | <a href='#'><i class='fa fa-trash js-delete' data-id='" + data + "'></i></a>";
}
}
]
});
t.on('order.dt search.dt', function () {
t.column(0, { search: 'applied', order: 'applied' }).nodes().each(function (cell, i) {
cell.innerHTML = i + 1;
});
}).draw();
$("#users").on("click", ".js-delete", function () {
var btn = $(this);
var confirm = btn.parents("table").attr("data-conf");
var dialogTitle = btn.parents("table").attr("data-title");
var btnOK = btn.parents("table").attr("data-btnOk");
var btnCancel = btn.parents("table").attr("data-btnCancel");
bootbox.dialog({
message: confirm,
title: dialogTitle,
buttons: {
main: {
label: btnCancel,
className: "btn-default",
callback: function () {
var result = "false";
}
},
success: {
label: btnOK,
className: "btn-primary",
callback: function () {
$.ajax({
url: "/api/users/" + btn.attr("data-id"),
method: "DELETE",
success: function () {
btn.parents("tr").remove();
}
});
}
}
}
});
});
});
</script>
}
This is how my tables looks (as you can see, the plus-sign is missing):

Your code seems to be fine. Plus sign only appears when viewing area is small enough and one of the columns become hidden.
There is no setting to force (+) sign to appear but you can use a trick with extra empty column and class none on it which will force column to always be hidden. See Class logic for more details.
See this jsFiddle for code and demonstration.

Related

DataTable doesn't show data

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

Can't read property 'replace' of null in angular data table

I wrote an angular datatable which fetches and populates the table with data from server. Code is given below:
HTML:
<table
class="table display table-striped table-hover table-bordered row-border hover responsive nowrap"
datatable
[dtOptions]="dtOptions"
datatable=""
#dataTable
id="issueTable"
>
<thead class="headColor">
<!-- <tr>
<th>Action</th>
</tr> -->
</thead>
<tbody>
<!-- <tr>
<td><button class="btn btn-primary btnColor" (click)="buttonInRowClick($event)">View</button></td>
</tr> -->
</tbody>
</table>
angular code:
import { Component, OnInit, Renderer, AfterViewInit, ViewChild } from '#angular/core';
import { Router, RouterLink } from '#angular/router';
import { routerTransition } from '../../router.animations';
import { DataTableDirective } from 'angular-datatables';
import 'datatables.net';
import 'datatables.net-bs4';
window['jQuery'] = window['$'] = $;
#Component({
selector: 'app-charts',
templateUrl: './issues.component.html',
styleUrls: ['./issues.component.scss'],
animations: [routerTransition()]
})
export class IssuesComponent implements OnInit {
#ViewChild(DataTableDirective)
datatableElement: DataTableDirective;
message = '';
title = 'angulardatatables';
#ViewChild('dataTable') table;
dataTable: any;
/**
* gets settings of data tables
*
* #type {DataTables.Settings}
* #memberof IssuesComponent
*/
constructor(private router: Router) { }
dtOptions: DataTables.Settings = {};
// someClickhandler(info: any): void {
// this.message = info.number + '-' + info.assignedto + '-' + info.company;
// console.log(this.message);
// }
ngOnInit(): void {
this.dtOptions = {
pagingType: 'full_numbers',
pageLength: 15,
processing: true,
responsive: true,
autoWidth: false,
dom: 'Bfrtip',
'ajax': {
url: 'http://localhost:8080/incident-updated',
type: 'GET',
dataSrc: 'result',
},
columns: [
{
title: 'Incident',
data: 'number'
},
{
title: 'Product',
data: 'u_product'
},
{
title: 'Status',
data: 'state'
},
{
title: 'Created By',
data: 'sys_created_by'
},
{
title: 'Group',
data: 'assignment_group'
},
{
title: 'Category',
data: 'u_category'
},
{
title: 'Updated on',
data: 'sys_updated_on'
},
{
title: null,
data: null,
render: function(data, type, full) {
return '<a class="btn btn-info btn-sm" href=#/>' + 'View' + '</a>';
}
}
]
// ,
// columnDefs: [
// {
// targets: -1,
// data: null,
// defaultContent: '<button>Click!</button>'
// }
// ]
};
this.dataTable = $(this.table.nativeElement);
console.log('table is ==>', this.dataTable);
$('#issueTable tbody').on('click', 'button', function () {
const data = this.dataTable.row($(this).parents('tr').data);
console.log('Data is ==>', data);
});
}
buttonInRowClick(event: any): void {
event.stopPropagation();
console.log('Button in the row clicked.');
this.router.navigate(['/event-viewer']);
}
wholeRowClick(): void {
console.log('Whole row clicked.');
}
// ngAfterViewInit() {
// this.renderer.listenGlobal('document', 'click', (event) => {
// if (event.target.hasAttribute("view-person-id")) {
// this.router.navigate(["/person/" + event.target.getAttribute("view-person-id")]);
// }
// });
// }
}
When I run that code, I get this error:
ERROR TypeError: Cannot read property 'replace' of null
at _fnSortAria (VM1053 scripts.js:16659)
at jQuery.fn.init.<anonymous> (VM1053 scripts.js:11820)
at VM1053 scripts.js:17237
at Function.map (VM1053 scripts.js:456)
at _fnCallbackFire (VM1053 scripts.js:17236)
at _fnDraw (VM1053 scripts.js:14107)
at _fnReDraw (VM1053 scripts.js:14150)
at _fnInitialise (VM1053 scripts.js:15333)
at loadedInit (VM1053 scripts.js:11893)
at HTMLTableElement.<anonymous> (VM1053 scripts.js:11905)
How do I fix this error?
I'm not sure about this but I think here is the problem:
{
title: null,
data: null,
render: function(data, type, full) {
return '<a class="btn btn-info btn-sm" href=#/>' + 'View' + '</a>';
}
}
Even if you don't use any field inside return, you should put some column name, for example data: 'u_product':
{
title: null,
data: 'u_product',
render: function(data, type, full) {
return '<a class="btn btn-info btn-sm" href=#/>' + 'View' + '</a>';
}
}
I recommend you to use the primary key column of the table, maybe in the future it will be useful in the button.

Reinitialization error while using datatables in Angular 7 while pulling data from an API

I'm trying to pull data from an API and display it in DataTables. Code is as given below:
<table class="table display table-striped table-hover table-bordered row-border hover" [dtOptions]="dtOptions" datatable="" #dataTable></table>
JavaScript:
#ViewChild(DataTableDirective)
#ViewChild('dataTable') table;
datatableElement: DataTableDirective;
dataTable: any;
dtOptions: any;
message = '';
title = 'angulardatatables';
ngOnInit(): void {
this.dtOptions = {
pagingType: 'full_numbers',
pageLength: 15,
processing: true,
responsive: true,
dom: 'Bfrtip',
'ajax': {
url: 'http://localhost:8080/incident',
type: 'GET'
},
columns: [
{
title: 'Incident',
data: 'number'
},
{
title: 'Product',
data: 'u_product'
},
{
title: 'Status',
data: 'incident_state'
}
]
};
this.dataTable = $(this.table.nativeElement);
this.dataTable.DataTable(this.dtOptions);
}
When I run that code, I get below error:
DataTables warning: table id=DataTables_Table_0 - Cannot reinitialise DataTable. For more information about this error, please see http://datatables.net/tn/3
I made sure that datatables for my node hasn't bee initialized already and I'm using technique given in this link and this link.
How can I fix this error?
Fixed it!
New code is:
<table class="table display table-striped table-hover table-bordered row-border hover" datatable [dtOptions]="dtOptions" datatable="" #dataTable>
</table>
JavaScript:
#ViewChild(DataTableDirective)
datatableElement: DataTableDirective;
message = '';
title = 'angulardatatables';
constructor(private router: Router) {}
dtOptions: DataTables.Settings = { };
ngOnInit(): void {
this.dtOptions = {
pagingType: 'full_numbers',
pageLength: 15,
processing: true,
responsive: true,
dom: 'Bfrtip',
'ajax': {
url: 'http://localhost:8080/incident',
type: 'GET',
dataSrc: "result"
},
columns: [
{
title: 'Incident',
data: 'number'
},
{
title: 'Product',
data: 'u_product'
},
{
title: 'Status',
data: 'state'
}
]
};
}

Creating Vue Search Bar | How to hide/show data based on input?

I am creating a dynamic search bar that will filter a sidebar full of names based on user input. However, I am having trouble temporarily hiding and showing data based on the search bar's value on keyup. What is the best way to achieve this the "Vue way"?
On keyup, I want to filter through all of the this.people data and only show names that contain the value of the search input.
Below is what my code looks like
Vue.component('sidebar',{
props: ['people', 'tables'],
data: () => {
return {
fullName: ''
}
},
computed: {
computed() {
return [this.people, this.tables].join()
}
},
template:
`
<div id="sidebarContain" v-if="this.people">
<input id="sidebar-search" type="text" placeholder="Search..." #keydown="searchQuery">
<select id="sidebar-select" #change="sidebarChanged">
<option value="AZ">A-Z</option>
<option value="ZA">Z-A</option>
<option value="notAtTable">No Table</option>
<option value="Dean's Guest">Dean's Guest</option>
<option value="BOO | VIP">BOO | VIP</option>
</select>
<div v-for="person in people" :class="[{'checked-in': isCheckedIn(person)}, 'person']" :id="person.id" :style="calcRegColor(person)">
<span v-if="person.table_name">{{person.first_name + ' ' + person.last_name + ' - ' + person.table_name}}</span>
<span v-else>{{person.first_name + ' ' + person.last_name}}</span>
</div>
</div>
`,
methods: {
isCheckedIn(person) {
return person.reg_scan == null ? true : false;
},
isHidden(person)
{
console.log("here");
},
calcRegColor(person)
{
switch(person.registration_type)
{
case "Dean's Guest" :
return {
color: 'purple'
}
break;
case "BOO | VIP" :
return {
color: 'brown'
}
break;
case "Student" :
return {
color: 'green'
}
break;
case "Faculty":
case "Staff":
return {
color: 'blue'
}
break;
case "Alumni Club Leader":
return {
color: 'gold'
}
break;
case "Table Guest" :
return {
color: 'pink'
}
break;
default:
return {
color: 'black'
}
}
}
},
watch: {
computed() {
console.log("People and Tables Available");
}
}
});
var app = new Vue({
el: '#main',
data: {
tables: {},
people: [],
currentAlerts: [],
lastDismissed: []
},
methods: {
loadTables() {
$.ajax({
method: 'POST',
dataType: 'json',
url: base_url + 'users/getTableAssignments/' + event_id
}).done(data => {
this.tables = data;
});
},
loadPeople() {
$.ajax({
method: 'POST',
dataType: 'json',
url: base_url + 'users/getParticipants2/' + event_id
}).done(data => {
this.people = data;
this.sortSidebar(this.people);
});
},
loadCurrentAlerts() {
$.ajax({
method: 'POST',
dataType: 'json',
url: base_url + 'alerts/getAlerts/' + event_id
}).done(data => {
this.currentAlerts = data;
});
},
loadLastDismissed(num = 15)
{
$.ajax({
method: 'POST',
dataType: 'json',
url: base_url + 'alerts/getLastDismissed/' + event_id + '/' + num
}).done(data => {
this.lastDismissed = data;
});
},
setRefresh() {
setInterval(() => {
console.log("Getting People and Tables");
this.loadPeople();
this.loadTables();
}, 100000);
},
makeTablesDraggable() {
$(document).on("mouseenter", '.table', function(e){
var item = $(this);
//check if the item is already draggable
if (!item.is('.ui-draggable')) {
//make the item draggable
item.draggable({
start: (event, ui) => {
console.log($(this));
}
});
}
});
},
makePeopleDraggable() {
$(document).on("mouseenter", '.person', function(e){
var item = $(this);
//check if the item is already draggable
if (!item.is('.ui-draggable')) {
//make the item draggable
item.draggable({
appendTo: 'body',
containment: 'window',
scroll: false,
helper: 'clone',
start: (event, ui) => {
console.log($(this));
}
});
}
});
}
makeDroppable() {
$(document).on("mouseenter", ".dropzone, .table", function(e) {
$(this).droppable({
drop: function(ev, ui) {
console.log("Dropped in dropzone");
}
});
});
}
},
mounted() {
this.loadTables();
this.loadPeople();
this.loadCurrentAlerts();
this.loadLastDismissed();
this.setRefresh();
this.makeTablesDraggable();
this.makePeopleDraggable();
this.makeDroppable();
}
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.4.2/vue.js"></script>
</head>
<div id="app">
<sidebar :people="people" :tables="tables"></sidebar>
</div>
You can change the people property in sidebar into a computed property, which will be calculated based on user's input.
So change the sidebar code to
<div v-for="person in filteredPeople" :class="[{'checked-in': isCheckedIn(person)}, 'person']" :id="person.id" :style="calcRegColor(person)">
<span v-if="person.table_name">{{person.first_name + ' ' + person.last_name + ' - ' + person.table_name}}</span>
<span v-else>{{person.first_name + ' ' + person.last_name}}</span>
</div>
and add a computed property
computed: {
filteredPeople () {
// Logic to filter data
}
}
A foolish aproach that I use, without computed properties:
JS:
new Vue({
el: '#app',
data: {
list: [],
filteredList: []
},
mounted(){
this.filteredList = this.list
},
methods: {
filter(e){
if(e.target.value === '') this.filteredList = this.list
else {
this.filteredList = []
this.list.forEach(item=>{
if(list.name.includes(e.target.value)) this.filteredList.push(item)
})
}
}
}
})
The "name" property of list object can be changed to whatever property you want to look for.
HTML:
<input #keyup="filter" id="search" type="search" required>

How to add a link button in knockout grid using MVC

I am new to knockout and MVC. I wanted to add a link button(delete) which will delete the record that is displayed in my knockout grid. I really dont have any idea how to achieve this. I have the following code that displays the record using the KO grid. Now I want to add a link button in the grid to delete the record
CONTROLLER:
public JsonResult GetResult()
{
GetResultRequest req = new GetResultRequest() { AcctID=57345, PartyType=2 };
var getResultInfo = WSHelper.WsService.GetResults(req);
return Json(getResultInfo.Signers, JsonRequestBehavior.AllowGet);
}
VIEW:
#Styles.Render("~/Content/css")
#Scripts.Render("~/bundles/SafeHarborBundle")
<script src="~/Scripts/koGrid-2.1.1.js"></script>
<script type="text/javascript">
var dataViewModel = ko.mapping.fromJS(#Html.Raw(Json.Encode(Model)));
<div id="gridSigner">
<div id="grids123" style="height: 700px; width: 650px;"
data-bind="koGrid: {
data: gridItems, columnDefs: [{ field: 'AcctID', displayName: 'AcctID', width: '150' },
{ field: 'FName', displayName: 'First Name', width: '150' },
{ field: 'LName', displayName: 'Last Name', width: '150' },
{ field: 'AliasFName', displayName: 'Alias First Name', width: '150' },
{ field: 'SSN', displayName: 'AcctID', width: '150' }],
autogenerateColumns: false,
isMultiSelect: false,
showFilter: true,
showColumnMenu: true,
enablePaging: false,
displaySelectionCheckbox: false,
enableColumnResize: false,
multiSelect: false
}">
JQUERY FILE:
$(document).ready(function () {
loadApplication(dataViewModel);
ko.applyBindings(Gridviews, document.getElementById('gridSigner'));
});
function loadApplication(initialData) {
self = this;
self.ViewModel = initialData;
self.BranchOptions = ko.observableArray([]);
self.AcctTypeOptions = ko.observableArray([]);
self.OriginationOptions = ko.observableArray([]);
self.Message = ko.observable();
SearchSignerData();
ko.applyBindings(self, document.getElementById('main-search'));
}
SearchSignerData = function () {
$.ajax({
type: "Get",
url: "/SafeHarborApp/GetResult",
contentType: 'application/json',
async: true,
cache: false,
beforeSend: function () {
},
success: function (result) {
alert(result[0].AcctID.toString());
if (result.length != 0) {
$.each(result, function (i, item) {
Gridviews.gridItems.push(item);
});
}
else {
Gridviews.gridItems.removeAll();
alert("No Records found");
}
},
complete: function () {
},
error: function (xhr, textStatus, errorThrown) {
//alert(jqXHR.responseText);
var title = xhr.responseText.split("<title>")[1].split("</title>")[0];
alert(title);
// Handle error.
}
});
}
The above code works fine in displaying the record in the KO grid. However, I dont know how to add a delete button in the displayed KO grid now. I tried searching for it but was not able to find anything useful that will get me the result. Please help...
Use CellTemplate in ko grid.plese see code below
<script type="text/javascript">
self.NoOfAccountColumn = '<a data-bind="value: $parent.entity" onclick="Popup(this.value)">No Of Account</a>';
self.Delete = '<a data-bind="value: $parent.entity" onclick="deleteRow(this.value)">Delete</a>';
function Popup(rowItem) {
alert(rowItem.AffinityNum + ' ' + rowItem.ClientName + ' : NoOfAccount Clicked');
}
function deleteRow(rowItem) {
alert(rowItem.AffinityNum + ' ' + rowItem.ClientName + ' : Delete Clicked');
}
function isDoubleClick(oldValue, currentValue) {
var responseTime = 400;
if ((currentValue - oldValue) <= responseTime) {
self.clickTime = currentValue;
return true;
}
self.clickTime = currentValue;
return false;
};
</script>
<script src="~/Scripts/Packages/koGrid-2.1.1.js"></script>
<div id="disp">
<div id="grid" style="height: 200px; width: 600px"
data-bind="koGrid: {
data: BranchOptions,
afterSelectionChange: function (rowItem, event) {
if (event.type == 'click' && isDoubleClick(self.clickTime, event.timeStamp)) {
alert(rowItem.entity.ClientName + ' : Row DoubleClick');
}
},
columnDefs: [{ field: 'ClientName', displayName: 'Client Name', width: '*', },
{ field: 'AffinityNum', displayName: 'Affinity Num', width: '*', cellTemplate: NoOfAccountColumn },
{ field: 'AffinityID', displayName: 'Affinity ID', width: '*', cellTemplate: Delete }],
autogenerateColumns: false,
isMultiSelect: false,
showFilter: true,
showColumnMenu: true,
enablePaging: false,
displaySelectionCheckbox: false,
enableColumnResize: true,
multiSelect: false
}">
</div>
</div>