I have a list of people that can be teachers or students (but not both). I have json data
{id:0,name:joe,isStudent:0,IsTeacher:0}
as the source for a bootstrap-table. I have used the column's data-formatter to format the the checkboxs in 2 columns
function formatStudent(value, row, index) {
return '<input type="checkbox" id="d_' + row["id"] +'"' + ((value != 0) ? ' checked ' : '') + '>';
}
There is another formatter for the Teacher column.The bootstrap-table renders properly with 2 checkboxes per row however, when I click on a checkbox - i get an error "Cannot read property of 'click' of undefined.
you can use 'data-events' to handle your events:
html:
<table id="table">
<thead>
<tr>
<th data-field="name">Name</th>
<th data-field="isStudent"
data-formatter="formatStudent"
data-events="studentEvents">Is Student</th>
<th data-field="isTeacher"
data-formatter="teacherStudent"
data-events="teacherEvents">Is Teacher</th>
</tr>
</thead>
</table>
js:
var data = [
{id: 0, name: 'joe1', isStudent: 0, isTeacher: 0},
{id: 1, name: 'joe2', isStudent: 1, isTeacher: 0},
{id: 2, name: 'joe3', isStudent: 0, isTeacher: 1},
{id: 3, name: 'joe4', isStudent: 1, isTeacher: 1},
{id: 4, name: 'joe5', isStudent: 0, isTeacher: 0}
];
$(function () {
$('#table').bootstrapTable({
data: data
});
});
function formatStudent(value, row, index) {
return '<input type="checkbox" id="d_' + row["id"] +'"' + ((value != 0) ? ' checked ' : '') + '>';
}
window.studentEvents = {
'click :checkbox': function (e, value, row, index) {
// do something
}
};
function teacherStudent(value, row, index) {
return '<input type="checkbox" id="d_' + row["id"] +'"' + ((value != 0) ? ' checked ' : '') + '>';
}
window.teacherEvents = {
'click :checkbox': function (e, value, row, index) {
// do something
}
};
Docs here: http://bootstrap-table.wenzhixin.net.cn/documentation/#column-options
Related
In vis.js, i can add easily an edge (ex function test) but i can't remove an existing edge (ex function test 1). Why ?
Unfortunately, i can't access now to documentation : "There isn't a GitHub Pages site here" for visjs.org. Thanks !
<input onclick=test() type="button" value="add edge 1 to 4 : ok">
<input onclick=test1() type="button" value="remove edge 1 to 2: not ok">
<div id="mynetwork"></div>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/vis/4.21.0/vis.js"></script>
<script type="text/javascript">
function test(){
data.edges.add([{from: 1, to: 4}]);
}
function test1(){
data.edges.remove([{from: 1, to: 2}]);
}
// GENERAL TEST
var nodes = [
{id: 1, label: 'Node 1'},
{id: 2, label: 'Node 2'},
{id: 3, label: 'Node 3'},
{id: 4, label: 'Node 4'}
];
var edges = [
{from: 1, to: 2},
{from: 1, to: 3},
{from: 2, to: 4}
];
nodesd = new vis.DataSet(nodes);
edgesd = new vis.DataSet(edges);
var container = document.getElementById('mynetwork');
var data = {
nodes: nodesd,
edges: edgesd
};
var options = {
nodes: {
size:15
},
edges: {
color: {
inherit: "both"
}
}
};
network = new vis.Network(container, data, options);
</script>
It's ok now !
I can do it with "id" for edges :
var edges = [
{id:1, from: 1, to: 2},
{id:2, from: 1, to: 3},
{id:3, from: 2, to: 4},
{id:4, from: 2, to: 5}
];
function test1(){
data.edges.remove([1]);
}
Here's an updated solution for anyone in the future that's stuck.
Let's say you initialized the network like so:
let network = new vis.Network(...);
let NODE_ID_1 = ...;
let NODE_ID_2 = ...;
Add a node connection:
network.body.data.edges.add({
'from': NODE_ID_1,
'to': NODE_ID_2
});
Remove a node connection:
let edges = network.getConnectedEdges(NODE_ID_1);
for(let edge of edges) {
if(NODE_ID_2 == network.body.edges[edge].to.id) {
network.body.data.edges.remove(edge);
break;
}
}
Helpful link: https://github.com/visjs/vis-network/blob/master/lib/network/modules/EdgesHandler.js
How to dynamically change exportable Datatable button names after they have already instantiated? Or how do I get my fnDeleteRow method to "activate" dynamically so that the existing buttons dynamically rename themselves? If they don't refresh themselves, I would like for the Do Stuff button to change the names of the other two (Excel and PDF) button names. (Isn't fnDeleteRow supposed to update ALL parts of the datatable? Are the button names cached?)
Here's part of the datatabe:
,"dom": 'B<"ui-toolbar ui-widget-header ui-corner-tl ui-corner-tr ui-helper-clearfix">'
,"columnDefs": [
{
"targets": [ 0, 1, 2, 3],
"visible": false,
"searchable": false
}
]
, buttons: [
{
extend: 'excelHtml5',
name: 'excelBtn',
text: function ( dt, button, config ) {
return 'Export all ' + dt.data().count() + ' entries to Excel'
}
},
{
extend: 'pdfHtml5',
orientation: 'landscape',
name: 'pdfBtn',
action: function(e, dt, button, config) {
config.text = 'Export all ' + dt.data().count() + ' entries to PDF';
$.fn.dataTable.ext.buttons.pdfHtml5.action(e, dt, button, config);
}
,header: true
,title: 'System'
,fontSize: '15'
,exportOptions: {
columns: [ 0, 1, 2, 3]
}
,customize: function ( doc ) {
doc["footer"] = function(currentPage, pageCount) {
return { text: ' Page ' + currentPage.toString() + ' of ' + pageCount + ' \r \n ' + getCurrentDateTime() , alignment: 'center' };
};
doc.content.splice( 1, 0, {
margin: [ 0, 0, 0, 12 ],
alignment: 'center',
bold: true,
style: 'header',
text: 'All Search Results'
}
);
}
},
{
text: 'Do Stuff',
action: function ( e, dt, node, config ) {
alert( 'Button to DO Stuff activated' );
if (confirm('Are you sure you want to "Do Stuff"?') == true) {
$.ajax({
method: "POST",
url: "...",
contentType: 'application/json',
data: {items: stuffToDo, year:$('#year').val()},
success: function( data, textStatus, jqXHR) {
Blockquote
Inside success (here), insert/modify code (or buttons.text above?) to update other button names after (this) button was pressed and all buttons were previously already initialized
??($('#searchDatatableResultsTable').dataTable()).button('pdfBtn:name' )???
In the snippet below I'd expect row a to have the class new-entry and row c to have the class moving-up but neither does.
I'm certain this is a silly mistake but I can't see it
Handlebars.registerHelper("newEntry", function() {
return this.newEntry ? 'class="new-entry"' : '';
});
Handlebars.registerHelper("movingUp", function() {
return this.movingUp ? 'class="moving-up"' : '';
});
var source = document.getElementById('leaderboard-template').innerHTML;
var template = Handlebars.compile(source);
var outlet = document.getElementById('outlet');
outlet.innerHTML = template({leaders: [
{name: 'a', signature_count: 10, newEntry: true},
{name: 'b', signature_count: 8},
{name: 'c', signature_count: 6, movingUp: false},
]});
.new-entry {
background-color:red;
}
.moving-up {
color:red;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.0.6/handlebars.min.js"></script>
<script id="leaderboard-template" type="text/x-handlebars-template">
<table>
<thead>
<th>Constituency</th>
<th>Votes</th>
</thead>
<tbody>
{{#leaders}}
<tr {{newEntry}}>
<td>{{name}}</td>
<td><span {{movingUp}}>{{signature_count}}</span></td>
</tr>
{{/leaders}}
</tbody>
</table>
</script>
<div id="outlet"></div>
Handlebar converts the return value of a helper to an HTML escaped string. Use Handlebars.SafeString like this if you don't want that:
Handlebars.registerHelper("newEntry", function() {
return new Handlebars.SafeString( this.newEntry ? 'class="new-entry"' : '' );
});
Handlebars.registerHelper("movingUp", function() {
return new Handlebars.SafeString( this.movingUp ? 'class="moving-up"' : '' );
});
In my mongo database i have number to defined the statut of the member, what I want to do is to get the name for this number, I did the function.
But i don't know how to use it with blaze.
In my html I have this :
{{#each usersList}}
<tr>
<td contenteditable="true">{{profile.firstName}}</td>
<td contenteditable="true">{{profile.lastName}}</td>
<td contenteditable="true">{{emails.[0].address}}</td>
<td contenteditable="true">{{profile.statut}}</td>
<td contenteditable="true">{{profile.subject}}</td>
<td contenteditable="true">{{profile.roles}}</td>
</tr>
{{/each}}
And in my js i have this :
Template.manageMember.helpers({
usersList : Meteor.users.find(),
'usersList.profile.statut': function(){
return userRightGetNameFromId(this);
}
});
I did that :
'usersList.profile.statut': function(){
return userRightGetNameFromId(this);
}
I understood, what i have i to is simply that :
in my helper:
userRightIdToName: function(context, options) {
if(context)
return userRightGetNameFromId(context);
}
And in my html:
<td contenteditable="true">{{emails.[0].address}}</td>
<td contenteditable="true">{{userRightIdToName profile.statut}}</td>
<td contenteditable="true">{{profile.subject}}</td>
But, I have a last problem with my function, it's return undefined, what can i do ?
This code is working, i have the number:
if(context)
return context;
}
My function:
userRightGetNameFromId = function(id){
$.each(USER_RIGHT, function(key, item) {
if (item.NUM == parseInt(id))
{
return item.NAME;
}
});
}
And my table:
USER_RIGHT =
{
STUDENT_1:
{
NUM: 1,
NAME: 'First'
},
STUDENT_2:
{
NUM: 2,
NAME: 'Second'
},
TUTOR:
{
NUM: 3,
NAME: 'Tutor'
},
RC:
{
NUM: 4,
NAME: 'RC'
},
RM:
{
NUM: 5,
NAME: 'RM'
},
RT:
{
NUM: 6,
NAME: 'RT'
},
ADMIN:
{
NUM: 7,
NAME: 'Admin'
}
};
Meteor doesn't wait that the function is finished ?
Hi is there any way to display appointments for the selected dates in the Kendo calender control?
Something like, if I've an appointment on 1st Jan my calender should show a message along with date (in the same kendo calender control). And the remaining dates would be normal style only.
You can show custom content on each date by defining a template function when you declare the calendar. This function will be called for each date shown in the calendar. The following example shows how to do this:
// Define dates that have appointments
var calDates = [];
calDates[+new Date(2013, 0, 1)] = [{ Description: "Appointment foo", Time: "09:00"}];
calDates[+new Date(2013, 0, 2)] = [{ Description: "Appointment bar", Time: "10:00" }, { Description: "Appointment baz", Time: "12:00"}];
// Declare Kendo Calendar
$("#div1").kendoCalendar({ "value": new Date(2013, 0, 1, 0, 0, 0, 0), "month": { "content": "#= BuildDateMarker(data) #"} });
// Template function
function BuildDateMarker(data) {
// Get any appointments for this date
var appointments = calDates[+data.date];
if (!appointments || appointments == 'undefined') {
// No appointments for this date, so return default marker (day of the month)
return data.date.getDate();
}
// Open marker
var marker = '<div class="appointments" title="' + data.date + '">';
// Add item for each of this date's appointments
for (var i = 0; i < appointments.length; i++) {
var appointment = appointments[i];
marker += '<span class="appointment">' + appointment.Description + ', at ' + appointment.Time + '</span>';
}
// Close marker
marker += '</div>';
return marker;
}