All geek questions in one place

    Using jQuery to sort or drop to place items in categories?

    I am trying to post products in cateogories e.g.

    <ul id="Category1"></ul>
    <ul id="Category2"></ul>
    
    <ul id="Available">
     <li id="prod1">Product1</li>
     <li id="prod2">Product2</li>
    </ul>
    

    I want to drop the available products into the category, and when it fell to send the update back through ajax. It really doesn't matter what is sent back, whether it is an updated category or all categories.

    $(document).ready(function() {
        $("tr:even").css("background", "#f7f7f7");
        $("ul.drop").sortable({
            connectWith: 'ul',
            tolerance: 'pointer',
            stop: function(ev, ui) {
                 ?????
            }
        });
    });
    

    Can I do this work, or should I use drag and drop?

    +3
    jquery jquery-ui
    GP Oct 08 '09 at 19:43
    source share
    1 answer

    Hi This is the best example, but it works:

    http://jsfiddle.net/marcosfromero/xpmAt/

    $("ul.basket").sortable({
        connectWith: 'ul.basket',
        tolerance: 'pointer',
        stop: function(event, ui) {
            // Get all Category1 and Category2 selected products and
            // populate matching fields
            jQuery('#selected1').val(jQuery('#Category1 li').map(function() {return this.id;}).get().join(','));
            jQuery('#selected2').val(jQuery('#Category2 li').map(function() {return this.id;}).get().join(','));
        }
    });
    
    +1
    marcosfromero Mar 15 '11 at 3:23
    source share

    Source: https://habr.com/ru/post/1719656/

    More articles:

    • MYSQL table structure - database
    • What is a good gvim guifont for programming in C / C ++? - c ++
    • Rails ActiveRecord Table Indexes - When Should They Be Used? - mysql
    • ВычислСниС ΠΌΠ°ΠΊΡΠΈΠΌΠ°Π»ΡŒΠ½Ρ‹Ρ… ΠΈ ΠΌΠΈΠ½ΠΈΠΌΠ°Π»ΡŒΠ½Ρ‹Ρ… Π·Π½Π°Ρ‡Π΅Π½ΠΈΠΉ Π² массивС - arrays
    • RIA with ASP.NET - asp.net
    • Problem with UIViewWithTag 0 - iphone
    • Is this an abuse of the type system? - c #
    • Get duplicate key exception when deleting and re-adding child rows in Entity Framework - entity-framework
    • How can I build a string from a collection with Linq? - string
    • How (strategy) in unit test (get / set) properties in BDD style? - unit-testing

    All Articles

    Geek Questions | 2019