position the div correctly above the table

I am currently working on creating a scheduler that has specific requirements:

  1. Show the working hours for each resource
  2. Show the interviews, allow changing the interview duration by resizing, and move the interviews using drag-and-drop functionality.

I need assistance with the following:

  1. After building the schedule, how can I draw each interview to be placed on top of the schedule in the correct position?
  2. If there are multiple schedules drawn next to each other, is it possible to drag an interview from one schedule to another?

$.fn.scheduler = function(options) {
  var context = $(this)
  var resources = {
      start: null,
      end: null,
      ownerId: null,
      ownerName: null,
      duration: 15, // 15 minutes,
      interviews: []
    }
    // build the scheduler

  function build() {
    if (options !== null && options !== undefined)
      $.extend(resources, options)
    var start = resources.start
    var end = resources.end
    var table = $('<table>')
    var temp = start
    console.log(start)
    while (temp < end) {
      console.log(temp)
      var tr = $('<tr>')
      var time = $('<td>')
      time.addClass('time')
      time.html(temp.getHours() + ':' + temp.getMinutes())
      tr.append(time)
      var event = $('<td>')
      event.addClass('event')
      tr.append(event)
      tr.appendTo(table)
      temp.setMinutes(temp.getMinutes() + resources.duration)
    }
    context.append(table)
  }
  build()
}
$(document).ready(function() {
  $('.scheduler').scheduler({
    start: new Date(2015, 11, 21, 9, 0, 0),
    end: new Date(2015, 11, 21, 17, 0, 0),
    ownerId: 1196,
    interviews: [{
      id: 111,
      start: new Date(2015, 11, 21, 11, 35, 0),
      duration: 45
    }]
  })
})
.scheduler {
  height: 200px;
  overflow-y: scroll;
}
.scheduler table {
  border: 1px solid #ddd;
  border-collapse: collapse;
  ;
}
table {
  font-size: 1.0em;
}
table td {
  height: 20px;
  border-bottom: 1px solid #ddd;
}
table td.time {
  border-right: 1px solid #ddd;
}
.time {
  width: 70px;
  font-weight: bold;
  color: #c1c1c1;
}
.event {
  width: 160px;
}
.interview {
  position: absolute;
  width: 160px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class='scheduler'>

</div>

JSFIDDLE

Answer №1

If you're looking for solutions to the initial part of your query, consider these steps:

1- Revise your CSS with the following adjustments

.scheduler{
    font-family: Calibri;
    position: relative;
    height: 400px;
    overflow-y: scroll;
}
.interview {
    position: absolute;
    background-color: aqua;
    opacity: 0.5;
    width: 160px;
    border:1px solid #808080;
}

2- Incorporate the subsequent JS function into your scheduler

function showInterviews() {
        for (var interview in resources.interviews) {
            var iw = resources.interviews[interview]
            var timeStart = iw.start.getHours() * 60 + iw.start.getMinutes()
            var timeEnd = timeStart + iw.duration
            var result = context.find('.time').filter(function () {
                return $(this).data('start') <= timeEnd && $(this).data('end') >= timeStart;
            })
            if (result.length > 0) {
                var first = result.first().next()
                var position = first.position()
                console.log(first.css('font-size'))
                var div = $('<div>')
                div.addClass('interview')
                div.attr('start', timeStart)
                div.attr('end', timeEnd)
                div.attr('duration', iw.duration);
                div.css('top', position.top + 1)
                div.css('width', first.width()+1)
                div.css('height', (result.length - 1) * 24  - result.length)
                div.css('left', position.left + 1)
                div.appendTo(context)
            }
        }
    }

3- Enhance your build function to preserve the start and end times in the data attributes

var timeStart = temp.getHours() * 60 + temp.getMinutes()
var timeEnd = timeStart + resources.duration
time.attr('data-start', timeStart)
time.attr('data-end', timeEnd)

Description:

I- Techniques to identify the overlap between the interview block and the schedule table, particularly when dealing with time segments

  1. Convert each time slot to minutes by ( Hour * 60 + minutes) as start and compute the end of slot by start + duration
  2. Determine the common tds that intersect with the interview start and end by (
    td.start <= interview.end and td.End>=interview.start
  3. Omit the last item in the result set since your time slot starts at the previous slot's end time

II- Retrieve the initial element from the result and adjust the interview's top and left based on the position of the first td element.

III - The reason behind using the value 24 is unclear, experimenting with (first.height() + result.length) instead of 24 did not yield the expected outcome, seeking clarification from others might be beneficial.

Here's a functioning demonstration

Hopefully, this information proves useful to you

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to fetch HTML content using JavaScript?

I needed to incorporate JavaScript for fetching HTML code. I structured the HTML code in the following manner; <html> <div id="tesingCode"> <h1>Title</h1> <p>testOfCodetestOfCodetestOfCodetestOfCode</p> </div ...

Discrepancy in Table Alignment

I seem to be encountering an issue with the alignment of text in my table. It appears that there are differences in content among the columns, causing the misalignment. I have tried adding white-space within each table, but it doesn't solve the proble ...

Stop Chrome mobile from automatically detecting phone numbers

I encountered a problem with a webpage on Chrome mobile where text content was mistakenly detected as a phone number. Fortunately, I was able to resolve the issue on Safari by including a specific meta tag. <meta name="format-detection" conte ...

Swinging text using Javascript/JQuery on the edges of a container

I am looking to create a bouncing text effect within a specific div element (#header). The text successfully bounces off the right side, then reverses and hits the left side. However, the issue arises when it reaches the left side and begins moving right a ...

Executing a jQuery AJAX request for a second time

Upon hitting the submit button for the first time, the codes work successfully. However, upon hitting the button for the second time with correct email and password values, nothing happens and the user cannot log in. I have identified that the issue lies w ...

Unable to insert values into database using PHP

I've put together a user registration form using PHP, jQuery, and SQL. I have everything set up to send the details to the database via an AJAX request. The code is running smoothly without errors, but for some reason, the values are not being added t ...

Tips for reducing unwanted messages on a form

My website features a basic registration form where users can sign up for a newsletter by entering their email address. I am concerned about potential spammers flooding my system with fake email addresses. Does anyone have any suggestions on how to preven ...

There seems to be an issue in AngularJS 6 with trying to read a property that is undefined, resulting in a TypeError

I keep seeing the error message "Cannot read property '0' of undefined". This snippet shows my HTML code: <!-- ... --> <img src="{{hit._source.productPhoto[0].docURL}}"> Below is a snippet of my JSON data: "hits": [ { "_inde ...

What could be the issue causing the jQuery code from PHP to not function properly when echoed into another page via AJAX

I created an Ajax code in admin.php to communicate with viewcollege.php. However, the jQuery echo from viewcol.php is not functioning properly on admin.php. admin.php: <!-- To change this template, choose Tools | Templates and open the template in the ...

Python and website submission button without an action attribute

I'm currently working on a Python program that interacts with an online store. So far, I've successfully located the desired item and accessed its page using BeautifulSoup. However, I'm struggling with clicking the "Add to cart" button. Most ...

Allow for separation amongst my cellular components

I have a table with multiple cells and I would like to add some spacing between each <td> element. You can find an example of my code on JSFIDDLE. .line { border-bottom:1px solid black; } .textRotation { -webkit-transform: rotate(-90deg); ...

How VueJS v-if can cause the disappearance of footable attributes

I'm currently using Jquery footable for a table but couldn't find an equivalent in VueJS. My goal now is to be able to delete or restore rows in the table. When I delete a row, I use: $vm0.isVisible = false; // ( Each row is a vue component ) ...

Transfer all HTML variables using AJAX with jQuery

Is it possible to pass all HTML tag values to another file using AJAX? $.ajax({ url:"myp.php", type:'POST', data: //here I want to include all possible element values in the current HTML document }); Any suggestions or ideas on how to ...

Incorrect color change on button triggered by onMouse actions and state fluctuations

While creating a user profile on my app, I encountered an issue with button coloring. When I try to add color functionality to the button, it turns red instead of green and remains red even when the mouse is not hovering over it. My goal is to have the but ...

Show a popover within a parent div that has limited visible space due to its hidden overflow

Struggling with AngularJS, I can't seem to find a simple solution for this problem. In my code, there's a div element with the overflow: hidden property set due to an internal scrollbar. Inside this div, there's a dropdown menu that is trigg ...

Switch the parent container in AngularJS by utilizing ng-click functionality

Within two distinct containers, one container holds a button. Upon clicking it, this button should move to the second container. I am familiar with achieving this using jQuery: $(document).on('click', '.drag', function(){ if($(thi ...

Link functioning properly for one item but failing for another

I am facing an issue with my index.html file that contains the following code: <li> <a href="imprint.html#imprint-link"> <div class="main-menu-title">IMPRINT</div> </a> </li> Clicking on the "IMPRINT" link loa ...

Why is it that servlets are unable to send custom JSON strings, and why is it that Ajax is unable to receive them?

I have developed a servlet that responds with a simple JSON list: public void addCategory(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { logger.log(Level.INFO, "Adding the category"); ObjectifyS ...

Create a function that binds a select dropdown to each table column header using JavaScript Object Notation (JSON), and then populate an HTML table with the

I have a dynamic table populated with JSON data, and I would like to add a select dropdown for each column. The challenge is that the number of columns is not fixed and they are also populated by JSON. Therefore, I want the select dropdown at the top of ea ...

Localhost is fine, but Github pages are just not cooperating with Bootstrap

I am currently in the process of building a portfolio website using Bootstrap 4, animate.css, typed.js and my own custom css. When testing the site on localhost through VS Code, everything appears to be functioning correctly. However, upon viewing the sit ...