Custom column type
Jspreadsheet gives developers the ability to create their own custom columns. The following example shows how to integrate a third party clock plugin as a custom column on Jspreadsheet Pro v7+.
A time custom column based on the clockpicker plugin by weareoutman.
<html>
<script src="https://jspreadsheet.com/v7/jspreadsheet.js"></script>
<script src="https://jsuites.net/v5/jsuites.js"></script>
<link rel="stylesheet" href="https://jspreadsheet.com/v7/jspreadsheet.css" type="text/css" />
<link rel="stylesheet" href="https://jsuites.net/v5/jsuites.css" type="text/css" />
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery-clockpicker.min.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery-clockpicker.min.js"></script>
<div id="custom"></div>
<script>
let clockEditor = function() {
let methods = {};
methods.createCell = function(cell, value, x, y, instance, options) {
cell.innerHTML = value;
}
methods.updateCell = function(cell, value, x, y, instance, options) {
if (cell) {
cell.innerHTML = value;
}
}
methods.openEditor = function(cell, value, x, y, instance, options) {
// Create input from the helpers
let editor = jspreadsheet.helpers.createEditor('input', cell);
editor.value = value;
// Instance of the clock picker
$(editor).clockpicker({
afterHide:function() {
setTimeout(function() {
// To avoid double call
if (cell.children[0]) {
instance.closeEditor(cell, true);
}
});
}
});
editor.focus();
}
methods.closeEditor = function(cell, save) {
if (save) {
cell.innerHTML = cell.children[0].value;
} else {
cell.innerHTML = '';
}
return cell.innerHTML;
}
return methods;
}();
let data = [
['PHP', '14:00'],
['Javascript', '16:30'],
];
jspreadsheet(document.getElementById('custom'), {
data: data,
columns: [
{
type: 'text',
title: 'Course Title',
width: '300px'
},
{
type: clockEditor,
title: 'Time',
width: '200px'
},
],
license: 'NjhmMzBlOGQ4ODhlZTVkODk4ZGYzNjkwMGZkMGFkNThmYTljNTVhZGJiYjE1OTY2NmZmZmNkYmRlODYzYzFlNjU0YjVjYjJiZjQ0NTYyMzI2YWZmMmI1OGFlYzMxZWI4NTI5M2ViZGNlMWIxZjc2Y2M0NzRmMmMwZTAxOWRlMmQsZXlKamJHbGxiblJKWkNJNklpSXNJbTVoYldVaU9pSktjM0J5WldGa2MyaGxaWFFpTENKa1lYUmxJam94TnpZd01qWXdNelV4TENKa2IyMWhhVzRpT2xzaWFuTndjbVZoWkhOb1pXVjBMbU52YlNJc0ltTnZaR1Z6WVc1a1ltOTRMbWx2SWl3aWFuTm9aV3hzTG01bGRDSXNJbU56WWk1aGNIQWlMQ0p6ZEdGamEySnNhWFI2TG1sdklpd2lkMlZpWTI5dWRHRnBibVZ5TG1sdklpd2liRzlqWVd4b2IzTjBJbDBzSW5Cc1lXNGlPaUl6TkNJc0luTmpiM0JsSWpwYkluWTNJaXdpZGpnaUxDSjJPU0lzSW5ZeE1DSXNJbll4TVNJc0ltTm9ZWEowY3lJc0ltWnZjbTF6SWl3aVptOXliWFZzWVNJc0luQmhjbk5sY2lJc0luSmxibVJsY2lJc0ltTnZiVzFsYm5Seklpd2lhVzF3YjNKMFpYSWlMQ0ppWVhJaUxDSjJZV3hwWkdGMGFXOXVjeUlzSW5ObFlYSmphQ0lzSW5CeWFXNTBJaXdpYzJobFpYUnpJaXdpWTJ4cFpXNTBJaXdpYzJWeWRtVnlJaXdpYzJoaGNHVnpJaXdpWm05eWJXRjBJbDBzSW1SbGJXOGlPblJ5ZFdWOQ==',
});
</script>
</html>