2013-12-16 6 views
2

SortableRows 옵션을 사용할 수있는 jqGrid가 있습니다. 이전에는 행을 항상 정렬 할 수있었습니다. 행이 삭제되면 데이터베이스는 ajax 호출을 통해 업데이트됩니다. 이렇게하려면 update 옵션을 사용하고 있습니다.jqGrid 정렬 가능한 행, 특정 행에 대해서만 정렬 허용

이제 특정 행에 허용되지 않도록 정렬을 구현해야합니다. 즉, 표시되는 열 중 하나에 대해 "1"의 열 값을 가진 행입니다. 성공적으로 아약스 업데이트를 차단했지만 시각적으로 행은 여전히 ​​새 위치에 드롭됩니다. 행을 원래 위치로 시각적으로 되돌려 야합니다.

지금까지이 코드는 작동하지만 주석이있는 영역은 행을 이전 위치로 되 돌리는 방법과 관련되어 있습니다. 당신의 items (또는 cancel) 멤버를 지정하는 다음 행에 클래스를 추가하고하여 그들을로드 할 때 sortableRows 이후

jQuery("#all_driver_runs").jqGrid('sortableRows', { 
    update: function (ev, ui) { 
     //first check the value of the 'placed_in_runs' column 
     if ($('#all_driver_runs').jqGrid('getRowData', ui.item[0].id)['placed_in_run'] !== "1") { //here update the database 
      if (!ui.item[0].previousSibling) { 
       $.post("scripts/update_driver_run_sort.php", { 
        this_one: ui.item[0].id, 
        prev: 'none', 
        next: ui.item[0].nextSibling.id 
       }); 
      } else if (!ui.item[0].nextSibling) { 
       $.post("scripts/update_driver_run_sort.php", { 
        this_one: ui.item[0].id, 
        prev: ui.item[0].previousSibling.id, 
        next: 'none' 
       }); 
      } else { 
       $.post("scripts/update_driver_run_sort.php", { 
        this_one: ui.item[0].id, 
        prev: ui.item[0].previousSibling.id, 
        next: ui.item[0].nextSibling.id 
       }); 
      } 
     } else { 
      /* 
      *no DB update, and now I need to revert to previous position here ??? 
      */ 
     } 
    } 
}); 

답변

4

이 jQueryUI의 정렬 위젯과 호환됩니다, 당신은 정렬되는 행을 차단할 수 sortableRows '옵션이 있습니다.

따라서 클래스가 unmovable이라고 가정하면 ".jqgrow:not(.unmovable)"sortableRows에 전달할 수 있습니다. 예를 들어 :

$('#all_driver_runs').jqGrid('sortableRows', { 
    items: ".jqgrow:not(.unmovable)", 
    /* remaining options if needed */ 
}); 

행에 클래스를 추가하기 위해,이 answer를 참조하십시오.

+1

그건 좋은 물건입니다, 도움을 주셔서 감사합니다! 완벽하게 작동합니다. –

+0

이 설치 프로그램에서 문제가 발생했습니다. 이제 서로 옆에 움직이지 않는 행이 2 개있는 경우, 그 사이에 움직일 수있는 행을 놓을 수 없습니다. 나는 여전히 2 개의 움직일 수없는 행 사이에 움직일 수있는 행을 떨어 뜨릴 수 있기를 바랄 것이다. –

+1

'Cancel' 회원을보십시오. [이 바이올린] (http://jsfiddle.net/ssarabando/C58z8/)을 확인하십시오. "APPR"이있는 동안 "DSK1"열은 변환 할 수 없습니다. "APPR"을 주변에서 움직여보고 원하는 것이 맞는지보십시오. – ssarabando