How to Create Flexible, Sortable & Draggable Table with JQuery and BootStrap ~ Coding Savvy
FB Twitter Google
» »

How to Create Flexible, Sortable & Draggable Table with JQuery and BootStrap

Creating a sortable table can make lot of work easier and more understandable by users, In this tutorial we are going to use JQuery sortable and Draggable JQuery UI plugin to create a school times table that is useful for lecturers to arrange periods and times of lectures. This can be apply to many type of web applications on different cases depending on what the web developer prefers, This draggable style will improve user experience on your application and make it easier for lecturers to schedule lecture without stress.
How to Create Flexible, Sortable & Draggable Table with JQuery and BootStrap

Download Script Live Demo
Let start by creating the table that will hold out times table with html. the index.html file

<div class="container-fluid">
<div class="row"><div class="col-md-10">
<div class="tab-pane " id="programmes"><div class="panel panel-primary">
<div class="panel-heading">Department of Electrical/Electronics Engineering Times Table</div>
<div class="panel-body"><table class="table table-responsive table-bordered table-hover timet">
<tr ><th class="time"></th><th class="time">
<th class="time">9:00AM-10:00AM</th><th class="time">
10:00AM-11:00AM</th><th class="time">11:00AM-12:00NOON</th>
<th class="time">12:00NOON - 1:00PM</th><th class="time">
1:00PM-2:00PM</th><th class="time">2:00PM-3:00PM</th>
<th class="time">4:00PM-5:00PM</th>
<th class="time">5:00PM-6:00PM</th><tr>
<tr class="classes" ><th class="day">
MEC439</td><td colspan="2">GNS324</td>
</tr><tr class="classes" ><th class="day">
</tr><tr class="classes" ><th class="day">Wenesday</th>
CHE323</td></tr><tr class="classes" ><th class="day">Thursday</th><td >
<td colspan="2">CVE101</td><td>CVE101</td><td>CVE101</td><td>ABE373</td></tr><tr class="classes" >
<th class="day">Friday</th><td>GNS324</td><td>
<tr class="classes" ><th class="day">Saturday</th><td >
<div class="tab-pane " id="programmes"><div class="panel panel-primary">
<div class="panel-heading">All available Coursess in Electrical/Electronics Engineering Department.</div>
<div class="panel-body"><table class="table table-responsive table-bordered ">
<tr class="allcourse"><th class="rate">Compulsory</th>
<td>EEE123</td><td >MEE111</td></tr><tr class="allcourse"><th class="rate">Elective</th><td>
CVE101</td><td >MEE111</td><td>CEC439</td><td>
GSC324</td></tr><tr class="allcourse"><th class="rate">Required</th><td >GNS111</td>
</tr><tr class="allcourse">
<th class="rate" >Others</th>
<td id="fp">Single F/Period</td>
<td colspan="2" id="fp">Double F/Period</td>
Now let make our table flexible and organizeable with JQuery using the edepartment.js.
This Javascript file is doing a lot of thing and adding some useful function to our flexible table,
It make it easier for our table to delete manage and replace columns .
$(function() { });
var sortableln =0;
var copyHelper,moveHelper;
$( ".classes" ).sortable({ cursor:"move", helper:function(e,li){
moveHelper = li.clone().insertAfter(li);
return li.clone();
}, stop:function(){
moveHelper.attr('class','fp').html('Single F/Priod');
}, delay:150, zIndex:9999, items:"td:not(,th.time,td.fp)", connectWith:".classes", dropOnEmpty:true, receive:function(e,ui){
}, over:function(event,ui){
}, out:function(event,ui){
}, beforeStop:function(event,ui){
} } }).disableSelection();
$( ".allcourse" ).sortable({ helper:function(e,li){
copyHelper = li.clone().insertAfter(li);
return li.clone();
}, stop:function(){
copyHelper && copyHelper.remove();
}, items:"td:not(th.rate)", beforeStop:function(event,ui){
}, zIndex:9999, connectWith:".classes", dropOnEmpty:true, }).disableSelection();
var replaceFreeperiod = function(event,ui){
var aft = ui.item.after().next().next();
var bfr = ui.item.before().prev();
if (aft.attr('class')=='fp'){
if(confirm('Would you like to use this lecture to replace the highlighted free period on the right?')){
} else{aft.css({'color':'#333'});
} } if (bfr.attr('class')=='fp'){
if (confirm('Would you like to use this lecture to replace the highlighted free period on the left?')){
}else{ bfr.css({'color':'#333'});
} } } var fixhelper = function(e,tr){
var $originals = tr.children();
var $helper = tr.clone();
return tr;
$( ".classes" ).each(function(index){
if($(this).children().length > 10){
alert("This day has been filled up, You can not add more lectures, Please choose another day or subtitute the lectures.");
copyHelper && copyHelper.remove();
moveHelper && moveHelper.remove();
} });
function getClassNameWithSuffix(el){
var className= null;
var reg = /\w+\d+/;
$($(el).attr('class').split('')).each( function(){
return false;
} });
return className;
Was this article helpful?
Thanks! Your feedback helps us improve tutorials.

You May Also Like...

No comments:

Post a Comment