The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Sortable Div's UI Not Working Correct

  • This topic is empty.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
  • #204595

    I am working on sortable divs with bootstrap On my script I can only put in one col- size at a time. As shown on my codepen example.

    I would like to know if there is away on my javascript so the I do not have to enter the the column sizes but detects the column size instead.

    Any Suggestions



    You have to dynamically determine the layout. Here’s a quick example.

    $rows = $('.row');
    $rows.each(function(index, el) {
      $itemClass = $(this).find('.col').attr('class');
      $layout = $itemClass.slice(-1);
      $self = $(this);
        placeholder: 'col-md-' + $layout + ' placeholder',
        helper: 'clone',
        appendTo: document.body,
        opacity: 0.7,
        start: function(event, ui) {
          var $definedStyles = {
            height: ui.item.height() + 60 + 'px',
            padding: '2rem',
            border: '3px dotted #999',
            backgroundColor: '#ccc',
        stop: function(event, ui) {

    Hope that helps get you in the right direction.
    Best, Alen.


    @Alen. When I refresh my page they go back to old position is there any way to keep them in there new position after page refresh etc.


    @riwakawd you can’t unless you implement some kind of persistence layer. Once you refresh the page HTML/JS/CSS re-renders the page so your state is gone. You need to save it somehow, either in a database, cookie, application cache, service worker, etc…

    So the general process would be:

    1. On initial load, user requests the page, you display default sorting
    2. User sorts the items, you save those changes back to the persistence layer.
    3. Next time user requests the page, you would load the custom sorting from the persistence layer
Viewing 4 posts - 1 through 4 (of 4 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.