School timetable is example of how to use REDIPS.drag library. Page layout contains two tables – left table with school subjects and timetable on the right. After subject is placed to timetable, button in the same color will be displayed next to the subject (clone object).
The following code shows event.dropped() event handler (with logic for cloning DIV elements across a week).
rd.event.dropped = function () { var objOld = rd.objOld, // original object targetCell = rd.td.target, // target cell targetRow = targetCell.parentNode, // target row i, objNew; // local variables // if checkbox is checked and original element is of clone type // then clone spread subjects to the week if (document.getElementById('week').checked === true && objOld.className.indexOf('clone') > -1) { // loop through table cells for (i = 0; i < targetRow.cells.length; i++) { // skip cell if cell has some content // (first column is not empty because it contains label) if (targetRow.cells[i].childNodes.length > 0) { continue; } // clone DIV element objNew = rd.cloneObject(objOld); // append to the table cell targetRow.cells[i].appendChild(objNew); } } // print message only if target and source table cell differ if (rd.td.target !== rd.td.source) { printMessage('Content has been changed!'); } // show / hide report buttons reportButton(); };
Source code (including school timetable with save/recall table using PHP and MySQL) and detailed description of library can be found on Drag and drop table content with JavaScript.
Sorry! I think I meant to say “get the value of attributes”, not “get elements”. :)
Hi,
Is it possible to save content from more than one table? I see var content = REDIPS.drag.saveContent(‘table2’); in the script.js but how will I be able to differentiate between the two or more table ids?
Right now the tbl_id in redips_timetable auto increments, could I use that to differentiate for each table?
Never mind, I found how to do it with your AJAX example. Thanks for providing this library to the public!
Hello.
I try to fill left table (table1) with javascript and it doesn’t work (not draggable)
var eltab=document.getElementById(‘table1′);
var rc=eltab.rows.length;
// delete row except 2 first
for(var x=rc-1;x>1;x–)
{eltab.deleteRow(x);} // OK
var newRow=eltab.insertRow(2);
newRow.className=’dark’;
var newCell0=newRow.insertCell(0);
newCell0.innerHTML=”something”;
On my screen it’s correct but I cannot drag it.
Thank you.
newCell0.innerHTML=”something”;
On my screen it’s correct but I cannot drag it.
Thank you.
Hello,
OK I understand why and it runs correctly now.
I can save the clones by savecontent in Mysql -> it runs.
But now I want to read Mysql to see the clones I wrote before.
Is it possible ?
Thank you.
Hi, How can I extend the code that I get a dynamic calendar for the whole year with all days and weeks? Is it also possible to give to all the table cells in the schedule an automatic unique ID? Thank you so much :)
How do you save two subjects in the same cell if you change drop mode to multiple?
Hi. i am using this code in my administration area. I put multiple teachers in every day and hour (about 5) and it result in more than 100 positions in one week. The question is:
method GET is not good for me, it truncate at about 100 rows (too limited). I need to use POST method for content variable in script.js and read that variable in db_save.php, but i have no idea, $.ajax give my an error ($ not defined). Can you help with this, please? Thank you!
How to save the content in .net or aspx page
@cata mitu – Please see redips.save() method in example22. In this example form elements are send to the server using POST method. This code can be slightly modified for your case because AJAX call functionality is already built-in in REDIPS.drag lib.
@SIVA SEMMANKADU GANESAN – Client code is the same no mater what is on the server side. Server side should accept parameters, process and save to the database. Please see example03 where is prepared case for the PHP and MySQL.
Dear dbunic. Congratulations.
Is it possible to change the cell background color that can not be dropped
on start drag (event.clicked) ?
And back to original color (event.finish)
Hi
How can I change background color of blocked cell when star drag and turn original color when stop?
Example: Arts can’t placed in Monday. And Math dropped on 11:00.
I have no idea to give this feedback to user before hover de cell.
Thanks
Hi, event.moved() is called in the moment when DIV element is moved from its home position – this can be considered as start dragging. For drag stop please see description for event.dropped() and event.droppedBefore() handlers. With using this event handlers, it’s possible to write some custom JS code to change TD background colors.
dbunic
Sorry for the duplicate message, I thought the first one was not sent.
This is part of my code under construction. It’s working for now.
Thank you
I’m glad you solved the problem and using event.finish() is even better than my suggestion. Thank you for feedback :)