SORTABLE - FIRST TIME LOADING ISSUE
I have written following function on page which will get displayed in dialog box. When dialog box has opened first time the sortable list doesn't operate or i cant move any element but if i close dialog box and reopen it again then sortable works perfectly.
- $(function() {
- if($( "#sortablelist" )!=null){
- $( "#sortablelist" ).sortable({
- placeholder: "ui-state-highlight",
- opacity: 0.5,cursor: "move",
- forcePlaceholderSize: true,
- update : function () {
- var newOrdering = $("#sortablelist").sortable("toArray");
-
- var newOrderIds = new Array(newOrdering.length);
- var ctr = 0;
- // Loop over each value in the array and get the ID
- $.each(
- newOrdering,
- function(intIndex, objValue) {
- //Get the ID of the reordered items
- //- this is sent back to server to save
- newOrderIds[ctr] = objValue;
- ctr = ctr + 1;
- }
- );
-
- }
-
- }
- );
-
- $( "#sortablelist" ).disableSelection();
- }
- });
Tried to debug for the same and found that at first time the sortable list doesn't get initialized properly and throws error on update on line number 8 as 'Unable to get value of the property 'sortable': object is null or undefined'. Am i doing anything wrong here?