2017-02-05 3 views
0

Ich habe eine Jquery jtable, die eine untergeordnete Tabelle hat. Soweit ich sehen kann, ist es nach dem Beispiel in den Jtable Demos eingerichtet. Die Haupttabellen = (Kontakte) und die Kindtabellen (Kategorien) werden ohne Probleme angezeigt. Mein Problem ist, dass die Löschaktion für die untergeordnete Tabelle den Zeilenschlüsselwert (categoryID) nicht veröffentlicht, wie ich es erwarten würde, und ich kann nicht sehen, warum nicht. Die ähnliche Aktion auf dem Haupttisch macht es gut. Beachten Sie die zwei console.log-Zeilen in dem Code, der die postData-Variable ausgibt, der erste meldet die ID der Kontakt-Tabellenzeile (ID), aber der zweite gibt ein leeres Array statt der CategoryID aus. Jede Hilfe wird geschätzt.jtable Kindtabelle nicht POST Schlüsselwert

Dank

function ReturnAjax(theurl, postdata, errorfn) { 
    return $.ajax({ 
     url: theurl, 
     type: 'POST', 
     dataType: 'json', 
     data: postdata, 
     cache: false, 
     error: errorfn 
    });    
} 

    $('#ContactsTableContainer').jtable({ 
    title: 'Contacts', 
    paging: true, 
    pageSize: 30, 
    sorting: true, 
    defaultSorting: 'LastName ASC', 
    selecting: true, 
    selectOnRowClick: true, 
    openChildAsAccordion: true, 
    deleteConfirmation: false, 
    actions: { 
     listAction: function(postData, jtParams) { 
      console.log("ContactsTableContainer - Loading list from custom function..."); 
      return $.Deferred(function($dfd) { 
       $.ajax({ 
        url: 'ContactsData.php?action=list&jtStartIndex=' + jtParams.jtStartIndex + '&jtPageSize=' + jtParams.jtPageSize + '&jtSorting=' + jtParams.jtSorting, 
        type: 'POST', 
        dataType: 'json', 
        data: postData, 
        success: function(data) { 
         if(data['RowIDs']) { RowIDs = data['RowIDs'].toString().split(','); } 
         $dfd.resolve(data); 
        }, 
        error: MyError 
       }); 
      }); 
     }, 
     deleteAction: function(postData) { 
      console.log('deleting from contacts - custom function..., '+JSON.stringify(postData)); 
      $.when(
       ReturnAjax(
        'ContactsData.php?action=list&ContactID='+postData['ID'], 
        postData, 
        MyError 
       ) 
      ).then(
       function(data) { 
        if (data.Result != 'OK') { alert(data.Message); } 
        var msg = ''; 
        var len = data.Records.length; 
        if(len>0) { 
         msg = '\t'+data.Records[0].Category; 
         for(var i=1 ; i<len ; i++) { msg += '\n\t'+data.Records[i].Category; } 
         msg = 'Contact is in the following categories\n'+msg; 
        } 
        msg += '\n\nConfirm deletion of this contact'; 
        if(confirm(msg)) { 
         $.when(
          ReturnAjax(
           'ContactsData.php?action=delete', 
           postData, 
           MyError 
          ) 
         ).done(
          $('#ContactsTableContainer').jtable('reload') 
         ); 
        } else { 
         $('#ContactsTableContainer').jtable('reload'); // Had to put this here to ensure that same delete button could be used again 
        }  
       } 
      ).fail(function() { console.log('ajax call went wrong'); }); 
     }, // end of delete action 
    }, // end of actions 
    fields: { 
     ID: { 
      key: true, 
      create: false, 
      edit: false, 
      list: false, 
      visibility: 'hidden' 
     }, 
     Categories: { 
      title: '', 
      width: '5%', 
      sorting: false, 
      create: false, 
      display: function(contact) { 
       var $img = $('<img src="Images/layers.png" title="Show contact\'s categories" />'); 
       //Open child table when user clicks the image 
       $img.click(function() { 
        console.log('display function (contact)..., '+JSON.stringify(contact)); 
        $('#ContactsTableContainer').jtable(
         'openChildTable', 
         $img.closest('tr'), //Parent row 
         { 
          title: contact.record.Name + ' - Categories', 
          selecting: true, 
          selectOnRowClick: true, 
          actions: { 
           listAction: 'ContactsData.php?action=list&ContactID=' + contact.record.ID, 
           deleteAction: function(postData) { 
            console.log('deleting from custom category function..., '+JSON.stringify(postData)); 
            $.when(
             ReturnAjax(
              'ContactsData.php?action=deleteAssignment&ContactID=' + contact.record.ID, 
              postData, 
              MyError 
             ) 
            ).done(
             $('#ContactsTableContainer').jtable('reload') 
            ); 
           } 
          }, 
          fields: { 
           CategoryID: { key: true, create: false, edit: false, list: false, visibility: 'hidden' }, 
           ContactID: { type: 'hidden', defaultValue: contact.record.ID }, 
           Category: { title: 'Category' } 
          } 
         }, 
         function(data) { data.childTable.jtable('load'); } 
        ); 
       }); 
       //Return image to show on the person row 
       return $img; 
      } 
     }, 
     FirstName: { 
       title: 'Forename', 
       width: '25%', 
     }, 
     LastName: { 
       title: 'Surname', 
       width: '25%', 
     }, 
     HomePhone: { 
      title: 'Phone', 
      width: '15%', 
      sorting: false, 
     }, 
     Mobile: { 
      title: 'Mobile', 
      width: '15%', 
      sorting: false, 
     }, 
     Email: { 
      title: 'Email', 
      width: '20%', 
      sorting: false, 
     }, 
     Name: { 
       type: 'hidden' 
     }, 
    } 
}); 

//Load list from server 
$('#ContactsTableContainer').jtable('load'); 

Antwort

0

OK, ich löste es, sorry niemanden zu stören, die Zeit auf der Suche auf diesem verbracht hat. Das Problem war, dass die Namen meiner Kindtabellenvariablen falsch waren, sie sollten category_ID und Contact_ID

sein