2016-12-01 11 views
0

툴바 클릭을 통해 중첩 된 JQuery JTable에서 선택한 행을 찾는 데 문제가 있습니다.jQuery JTable ChildTable에서 선택한 행을 찾으려면 문제가 발생했습니다.

$(document).ready(function() { 
    $('#TableContainer').jtable({ 
     title: 'MyList', 
     sorting: true, 
     defaultSorting: 'list_id desc', 
     actions: { 
      listAction: 'lists_list_action.php?action=list', 
      updateAction: 'lists_list_action.php?action=update', 
     }, 

     fields: { 
      list_id: { title: 'Nr.', key: true, list: true, width: '10px', listClass: 'psg_list_center' }, 

      //CHILD TABLE "Abos" 
      abos: { 
       title: 'Abos', 
       width: '5%', 
       sorting: false, 
       edit: false, 
       create: false, 
       display: function (ListData) { 
        //Create an image that will be used to open child table 
        var $img = $('<img src="../../images/list_metro.png" title="manage Listabos" />'); 
        //Open child table when user clicks the image 
        $img.click(function() { 
          $('#TableContainer').jtable('openChildTable', 
          $img.closest('tr'), //Parent row 
          { 
           title: 'List: ' + ListData.record.list_name, 
           selecting: true,   //Enable selecting 
           multiselect: true,   //Allow multiple selecting 
           selectingCheckboxes: true, //Show checkboxes on first column 
           selectOnRowClick: false, //Enable this to only select using checkboxes 
           actions: { 
            listAction: 'lists_list_action.php?action=AbosList&ListId=' + ListData.record.list_id, 
            deleteAction: 'lists_list_action.php?action=AbosDelete&ListId=' + ListData.record.list_id, 
           }, 
           fields: { 
            list_id: { type: 'hidden', defaultValue: ListData.record.list_id }, 
            person_id: { key: true, create: false, edit: false, list: false }, 
            person_name: { title: 'Name', width: '40%' }, 
            created_name: { title: 'created from', create: false, edit: false }, 
            created_on: { title: 'created on', create: false, edit: false }, 
            updated_name: { title: 'updated from', create: false, edit: false }, 
            updated_on: { title: 'updated on', create: false, edit: false }, 
           }, 
           toolbar: { 
            items: [{ 
             //icon: '/images/trash.png', 
             text: 'remove selected Abos', 
             click: function() { 

              // here i need to something like this: 
              alert('list_id=' + record.list_id + ', person_id=' + record.person_id); 
              delete_abo(record.list_id, record.person_id); 

             } 
            }] 
           }, 
          }, function (data) { //opened handler 
           data.childTable.jtable('load'); 
          }); 
        }); 
        //Return image to show on the person row 
        return $img; 
       } 
      }, 

      list_name: { title: 'List Name' }, 
      list_description: { title: 'Description', type: 'textarea' }, 
      list_active: { title: 'activ', options: { 1: 'Yes', 0: 'No' } }, 
      list_allow_subscribe: { title: 'Subscribe erlaubt', options: { 1: 'Yes', 0: 'No' } }, 
      list_allow_unsubscribe: { title: 'Unsubscribe erlaubt', options: { 1: 'Yes', 0: 'No' } }, 
     }, 
    }); 
    $('#TableContainer').jtable('load'); 

}); 

아무도 아동 - 테이블의 선택된 행을 찾는 도구 모음 버튼을 클릭 섹션에서 도와 줄 수 :

이 잘 작동 내 중첩 테이블은? 마지막 부분은 "중첩되지 않은"부분에서 잘 작동하기 때문에

click: function() { 

    var $selectedRows = $('#TableContainer').jtable-child-table-container.jtable('selectedRows'); 

    if ($selectedRows.length > 0) { 
     $selectedRows.each(function() { 
      var record = $(this).data('record'); 
      alert('list_id=' + record.list_id + ', person_id=' + record.person_id); 
      //delete_abo(record.list_id, record.person_id); 
     }); 
    } else { 
     //No rows selected 
     alert('please select some rows first!'); 
    } 
} 

:

click: function (ListData) { 
    var $selectedRows = ListData.jtable('selectedRows'); 

나 :

click: function() { 
    var $selectedRows = $('#TableContainer').jtable-child-table-container.jtable('selectedRows'); 
    $('#TableContainer').jtable('delete', $selectedRows); 
} 

또는

나는 이런 식으로 뭔가를하려고 노력 내 프로그램, 하지만 어쨌든 해결에 오지 않았다 ...

도움 주셔서 감사합니다.

답변

0

마지막으로 해결책을 찾았습니다!

선택한 행 얻을 수있는 키 :

var $selectedRows = $('#TableContainer>.jtable-main-container>.jtable>tbody>.jtable-child-row .jtable-row-selected'); 

또는 전체 작업 기능 :

click: function() { 

var $selectedRows = $('#TableContainer>.jtable-main-container>.jtable>tbody>.jtable-child-row .jtable-row-selected'); 

if ($selectedRows.length > 0) { 
    $selectedRows.each(function() { 
     var record = $(this).data('record'); 
     alert('list_id=' + record.list_id + ', person_id=' + record.person_id); 
     //delete_abo(record.list_id, record.person_id); 
    }); 
} else { 
    //No rows selected 
    alert('please select some rows first!'); 
} }