Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

jQuery EasyUI Drag and Drop - Creating a School Timetable

jQuery EasyUI Drag and Drop - Creating a School Timetable

This tutorial will show you how to create a school timetable using jQuery EasyUI. We will create two tables: one showing school subjects on the left, and one showing the timetable on the right. You can drag a school subject and drop it onto a timetable cell. A school subject is a

element, and the timetable cell is an element.

Displaying the school subjects



    
                                                                                                                    
English
Science
    

Displaying the timetable



    
                                                                                                                                                                                                                                                                                              
MondayTuesdayWednesdayThursdayFriday
08:00
    

Dragging the school subjects on the left



    $('.left .item').draggable({

        revert:true,

        proxy:'clone'

    });

Dropping a school subject onto a timetable cell



    $('.right td.drop').droppable({

        onDragEnter:function(){

            $(this).addClass('over');

        },

        onDragLeave:function(){

            $(this).removeClass('over');

        },

        onDrop:function(e,source){

            $(this).removeClass('over');

            if ($(source).hasClass('assigned')){

                $(this).append(source);

            } else {

                var c = $(source).clone().addClass('assigned');

                $(this).empty().append(c);

                c.draggable({

                    revert:true

                });

            }

        }

    });

As you can see in the code above, when the user drags a school subject on the left and drops it into a timetable cell, the onDrop callback function will be called. We clone the source element dragged from the left and append it to the timetable cell. When dragging a school subject from one timetable cell to another, simply move it.

Download the jQuery EasyUI example

jeasyui-dd-timetable.zip