ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Sortable List Items using JavaScript Question

February 25, 2012 4:24pm

Subscribe [1]
  • #1 / Feb 25, 2012 4:24pm

    dodgson

    120 posts

    Hi There, I’m trying to find a way to make a sortable list using JavaScript. I have the sorting working… It’s grabbing the list items from the channel entries, but if you refresh the page the order goes back to the way it was entered in the channel entry. Does anyone know how to modify the row count or something like this to make the sorted move permanent.

    Attached is a screenshot of my initial tests. Please Ignore the layout 😊

    Thanks in advance.

  • #2 / Feb 25, 2012 10:26pm

    Bhashkar Yadav

    727 posts

    you can create a custom field (will be number) to manage the sort order. while sorting with Javascript, update this field of entries also according to sorted order of entries. for it you have to use ajax to update this custom field each time when sorting in being performed.

  • #3 / Feb 25, 2012 10:29pm

    dodgson

    120 posts

    Thanks Bhashkar, I’m going to look into how to implement your solution. I’ve never done anything like this before.

    Again, thank you.

  • #4 / Feb 25, 2012 11:51pm

    Bhashkar Yadav

    727 posts

    you’re welcome… 😊

  • #5 / Feb 26, 2012 9:16am

    dodgson

    120 posts

    hi Bhashkar,  I have been trying to get this thing to work, unfortunately I can’t seem to figure out how to get this to modify the entry in the database (I’m using Matrix for each entry). Below is some PHP that I found online that should do the trick, but I’m not sure how I can connect this to my database. the other issue is that this PHP is being called from within JavaScript. My PHP skills are very limited. Any suggestions?

    This is the JavaScript
    ————————————————————-

    [removed]
      // When the document is ready set up our sortable with it's inherant function(s)
      $(document).ready(function() {
        $("#test-list").sortable({
          handle : '.handle',
          update : function () {
        var order = $('#test-list').sortable('serialize');
        $("#info").load("process-sortable.php?"+order);
          }
        });
    });
    [removed]

     

    This is the PHP being called in from the JavaScript
    —————————————————————

    <?php
    foreach ($_GET['listItem'] as $position => $item) :
     $sql[] = "UPDATE `table` SET `position` = $position WHERE `id` = $item";
    endforeach;
    
    print_r ($sql);
    ?>
  • #6 / Feb 26, 2012 12:42pm

    Bhashkar Yadav

    727 posts

    Hi dodgson,

    you are going in right direction. first of all prepare a value pair i.e arrray of position and entry id.

    here is very good tutorial for it. please look at.

    i hope this would help you.

    please share your findings over it.


    Best Regards,

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases