2016-12-01 63 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 (ListData) { 
    var $selectedRows = ListData.jtable('selectedRows'); 

或:

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

或:

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!'); 
    } 
} 

因爲最後一部分以 「沒有嵌套」 部分工作正常我的程序, ,但我沒有來決議無論如何...

感謝您的幫助!

回答

0

finaly找到解決方案!

的關鍵是獲得所選行:

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!'); 
} }