Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 81688

Inline Move Up/Down

$
0
0
Hi,

I am needing to add options for 'move up' and 'move down', i.e. We have a list of items that have a position associated with them, effectively a priority which is the first column of my table. What I would like to do is when the user selects 'Move Up' alter the position for that record and submit the details without the need for the modal to open.

I have initialised the buttons like so
{ "mData": null, "sClass": "alignCenter", "sDefaultContent": '<span class="userUP"><img src="../images/general/move_up.png"></span>', "bSortable": false }

Clicking this button will launch the following function which is telling me the row, current position of the current row, position of the previous record. Down function is similar but gets the next record and checks the paging length to stop a record from trying to move down as this is server side.

// When UP is clicked
        $("#pipelineTBL span.userUP").live("click", function (){
                     
            // Get the row index for compare, index is zero based.
            var rowIndex = oTable.fnGetPosition($(this).closest('tr')[0]);

            // Collect position details of; Selected ROW, Previous ROW. 
            var row = this.parentNode.parentNode;
            var currentPos = oTable.fnGetData( $('td:eq(0)', row)[0] );

            var nPrev = oTable.fnGetAdjacentTr( row, false );
            var prevPos = oTable.fnGetData( $('td:eq(0)', nPrev)[0] );

            // Check if the top row has been selected.
            if( rowIndex == 0 )
            {
                // If UP was selected do nothing.
                alert('cannot move up');
            }
            else if((rowIndex + 1) == nPaging) // Determine if last row was selected.
            {
                alert('can move up');
            }
            else
            {
                alert('can move up')
            }
        });

Say there are 3 rows and the position cell for each is in order 1, 2, 3. If I click the UP button on the 2nd row I need the Position value to change to 1 (from 2) and the AJAX call be made to update the records followed by a redraw, so everything that happens nicely now using the modal I would like to happen without needing the modal.

The modal is useful for the additional details but sometimes a simple re-order is all that will be required.

Any guidance would be appreciated.

Thanks.

Viewing all articles
Browse latest Browse all 81688

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>