2013-05-09 39 views
0

我試圖使用上可以找到的數據表(CRUD)插件DataTables Data Manager (CRUD) Add-on數據表(CRUD) - 服務器端添加新記錄

到目前爲止一切,除了當我嘗試是工作的罰款,以添加新記錄。 我已經按照在例如指令該鏈接Adding Records上和WiKi Example

這是我使用插入新記錄

// Open the db connection 
    $link = dbConnect('dbname'); 
    $params = array(); 
    $options = array("Scrollable" => SQLSRV_CURSOR_KEYSET); 
    // Prepare the insert 
    $updateQuery = "INSERT INTO $tblname ($columns) VALUES ($valuesTemp)"; 
    $id = 0; 
    $entity_id = array(); 

    // Run the insert and if it's been succesful enter the if condition 
    if(sqlsrv_query($link, $updateQuery) == true){ 
     // Get the last inserted ID 
     $getId = "SELECT MAX(Entity_Id) AS 'Id' FROM HoldingTable WHERE Client_Id = '$client_id' AND Project_Id = '$project_id'"; 
     $result = sqlsrv_query($link, $getId, $params, $options); 
     while ($aRow = sqlsrv_fetch_array($result, SQLSRV_FETCH_NUMERIC)) 
     { 
      $entity_id = $aRow; 
     } 
     $id = $entity_id[0]; 
     // Close the connection. 
     sqlsrv_close($link); 
     // return the id 
     echo $id; 
    }else{ 
     // If the insert failed display an error 
     echo 'There\'s been an error: '; 
     if(($errors = sqlsrv_errors()) != null) { 
      foreach($errors as $error) { 
       echo "SQLSTATE: ".$error[ 'SQLSTATE']."<br />"; 
       echo "code: ".$error[ 'code']."<br />"; 
       echo "message: ".$error[ 'message']."<br />"; 
     } 
    } 
} 

如果運行螢火蟲並檢查網絡的代碼,我正如網站上的示例一樣正確地獲取數字ID,但在插入後嘗試刷新表時,我不斷收到帶有以下錯誤的彈出消息。

DataTables warning (table id = 'dataTable'): Requested unknown parameter 'Entity_Id' from the data source for row 2 (This number changes depending on how many rows I've got) 

該消息有兩條記錄,並在插入第三條記錄後。

我試着移動選擇,獲取插入前運行的id,但仍然得到相同的錯誤,並找不出原因。

這是數據表初始化:

oTable = $('#dataTable').dataTable({ 
     "bJQueryUI": true, 
     "sScrollX": "100%", 
     "sScrollXInner": "400%", 
     "sScrollY": calcDataTableHeight(), 
     "bScrollCollapse": false, 
     "bAutoWidth": false, 
     "bDeferRender": true, 
     "bPaginate": true, 
     "bProcessing": true, 
     "bServerSide": true, 
     "sAjaxSource": "/scripts/jmevent/dbhelper.php?Client_Id=<?php echo $client_id; ?>&Project_Id=<?php echo $project_id; ?>&System_Id=<?php echo $system_id; ?>&TableName=<?php echo $tblname;?>", 
     "sServerMethod": "POST", 
     "oLanguage": { 
      "sProcessing": "<img src='/content/images/spinner_squares_circle.gif' height='15px' width='15px' alt='' /> Processing" 
     }, 
     "aaSorting": [[ 1, "desc" ]], 
     "aoColumns": [ 
      { "mDataProp": "Entity_Id" , "bSortable":true, "bVisible": false, "sWidth" : "1%" }, 
      { "mDataProp": "External_Id" ,"bSortable":true, "sWidth" : "1%" }, 
      { "mDataProp": "Family_Name" ,"bSortable":true, "sWidth" : "5%" }, 
      { "mDataProp": "First_Name" ,"bSortable":true, "sWidth" : "5%" }, 
      { "mDataProp": "Prefix_Title" ,"bSortable":true, "sWidth" : "1%" }, 
      { "mDataProp": "Suffix_Title" ,"bSortable":true, "sWidth" : "1%" }, 
      { "mDataProp": "Company" ,"bSortable":true, "sWidth" : "2%" }, 
      { "mDataProp": "Address_1" ,"bSortable":true, "sWidth" : "2%" }, 
      { "mDataProp": "Address_2" ,"bSortable":true, "sWidth" : "2%" }, 
      { "mDataProp": "Address_3" ,"bSortable":true, "sWidth" : "2%" }, 
      { "mDataProp": "Address_4" ,"bSortable":true, "sWidth" : "2%" }, 
      { "mDataProp": "Zip_Code" ,"bSortable":true, "sWidth" : "1%" }, 
      { "mDataProp": "City" ,"bSortable":true, "sWidth" : "2%" }, 
      { "mDataProp": "Country_Code" ,"bSortable":true, "sWidth" : "1%" }, 
      { "mDataProp": "Telephone" ,"bSortable":true, "sWidth" : "2%" }, 
      { "mDataProp": "Telefax" ,"bSortable":true, "sWidth" : "2%" }, 
      { "mDataProp": "EMail" ,"bSortable":true, "sWidth" : "2%" }, 
      { "mDataProp": "EMail2" ,"bSortable":true, "sWidth" : "2%" }, 
      { "mDataProp": "Session_Id" ,"bSortable":true, "bVisible": false, "sWidth" : "2%" }, 
      { "mDataProp": "Gender" ,"bSortable":true, "sWidth" : "1%" }, 
      { "mDataProp": "JMUser_Id" ,"bSortable":true, "bVisible": false, "sWidth" : "1%" }, 
      { "mDataProp": "Password" ,"bSortable":true, "bVisible": false, "sWidth" : "1%" }, 
      { "mDataProp": "ExtraField01" ,"bSortable":true, "bVisible": true, "sWidth" : "2%" }, 
      { "mDataProp": "ExtraField02" ,"bSortable":true, "bVisible": true, "sWidth" : "2%" }, 
      { "mDataProp": "ExtraField03" ,"bSortable":true, "bVisible": true, "sWidth" : "2%" }, 
      { "mDataProp": "ExtraField04" ,"bSortable":true, "bVisible": true, "sWidth" : "2%" }, 
      { "mDataProp": "ExtraField05" ,"bSortable":true, "bVisible": true, "sWidth" : "2%" }, 
      { "mDataProp": "ExtraField06" ,"bSortable":true, "bVisible": true, "sWidth" : "2%" }, 
      { "mDataProp": "ExtraField07" ,"bSortable":true, "bVisible": true, "sWidth" : "2%" }, 
      { "mDataProp": "ExtraField08" ,"bSortable":true, "bVisible": true, "sWidth" : "2%" }, 
      { "mDataProp": "ExtraField09" ,"bSortable":true, "bVisible": true, "sWidth" : "2%" }, 
      { "mDataProp": "ExtraField10" ,"bSortable":true, "bVisible": true, "sWidth" : "2%" }, 
      { "mDataProp": "Mobile" ,"bSortable":true, "bVisible": true, "sWidth" : "2%" }, 
      { "mDataProp": "URL" ,"bSortable":true, "bVisible": true, "sWidth" : "2%" }, 
      { "mDataProp": "Passport_Number" ,"bSortable":true, "bVisible": true, "sWidth" : "2%" }, 
      { "mDataProp": "Nationality" ,"bSortable":true, "bVisible": true, "sWidth" : "2%" }, 
      { "mDataProp": "ID_Number" ,"bSortable":true, "bVisible": true, "sWidth" : "2%" }, 
      { "mDataProp": "Date_Of_Birth" ,"bSortable":true, "bVisible": true, "sWidth" : "2%" }, 
      { "mDataProp": "Special_Needs_Physical" ,"bSortable":true, "bVisible": true, "sWidth" : "3%" }, 
      { "mDataProp": "Special_Needs_Dietary" ,"bSortable":true, "bVisible": true, "sWidth" : "3%" }, 
      { "mDataProp": "First_Name_For_Badge" ,"bSortable":true, "bVisible": true, "sWidth" : "5%" }, 
      { "mDataProp": "Family_Name_For_Badge" ,"bSortable":true, "bVisible": true, "sWidth" : "5%" }, 
      { "mDataProp": "Biography" ,"bSortable":true, "bVisible": true, "sWidth" : "2%" }, 
      { "mDataProp": "VAT_Number" ,"bSortable":true, "bVisible": true, "sWidth" : "2%" }, 
      { "mDataProp": "Membership_No" ,"bSortable":true, "bVisible": true, "sWidth" : "2%" }, 
      { "mDataProp": "Participant_Template" ,"bSortable":true, "bVisible": true, "sWidth" : "1%" }, 
      { "mDataProp": "Language_Code" ,"bSortable":true, "bVisible": true, "sWidth" : "1%" } 
      ], 
     "sPaginationType": "two_button", //full_numbers,two_button 
     "bInfo": true, 
     "sSearch" : true, 
     "iDisplayStart": 0, 
     "iDisplayLength": 50, 
     "bLengthChange": true, 
     "aLengthMenu": [[10, 25, 50, 100, 250, 500, -1], [10, 25, 50, 100, 250, 500, "All"]], 
     "sDom": '<"H"hflip>rt<"F"ip>', 
     "fnRowCallback": function(nRow, aData, iDisplayIndex, iDisplayIndexFull) { 
      $(nRow).attr("id",aData['Entity_Id']); 
      return nRow; 
     } 
    }).makeEditable({sUpdateURL: "updatedata.php?Client_Id=<?php echo $client_id; ?>&Project_Id=<?php echo $project_id;?>&System_Id=<?php echo $system_id; ?>&TableName=<?php echo $tblname;?>", 
      sAddURL: "adddata.php?Client_Id=<?php echo $client_id; ?>&Project_Id=<?php echo $project_id;?>&System_Id=<?php echo $system_id; ?>&TableName=<?php echo $tblname;?>", 
      sDeleteURL: "deletedata.php?Client_Id=<?php echo $client_id; ?>&Project_Id=<?php echo $project_id;?>&System_Id=<?php echo $system_id; ?>&TableName=<?php echo $tblname;?>", 
      fnShowError: function (message, action) { 
       switch (action) { 
        case "update": 
         break; 
        case "delete": 
         break; 
        case "add":  
         $("#lblAddError").html(message); 
         $("#lblAddError").show(); 
         break; 
       } 
      }, 
      fnStartProcessingMode: function() { 
       $("#processing_message").dialog(); 
      }, 
      fnEndProcessingMode: function() { 
       $("#processing_message").dialog("close"); 
      }, 
     "aoColumns":[ 
         {}, //External_Id 
         {}, //Family_Name 
         {}, //First_Name 
         {}, //Prefix_Title 
         {}, //Suffix_Title 
         {}, //Company 
         {}, //Address_1 
         {}, //Address_2 
         {}, //Address_3 
         {}, //Address_4 
         {}, //Zip_Code 
         {}, //City 
         { 
          tooltip: 'Click to select country code', // Country_Code drop down 
          loadtext: 'Loading...', 
          data: '<?php print json_encode($country, JSON_HEX_APOS); ?>', 
          type: 'select', 
          submit: 'Ok' 
         }, 
         {}, //Telephone 
         {}, //Telefax 
         { 
          cssclass: "email" 
         }, //Email 
         {}, //Email2 
         {}, //Gender 
         {}, //ExtraField01 
         {}, //ExtraField02      
         {}, //ExtraField03 
         {}, //ExtraField04 
         {}, //ExtraField05 
         {}, //ExtraField06 
         {}, //ExtraField07 
         {}, //ExtraField08 
         {}, //ExtraField09 
         {}, //ExtraField10 
         {}, //Mobile 
         {}, //URL 
         {}, //Passport_Number 
         {}, //Nationality 
         {}, //ID_Number 
         { 

         }, 
         { //Date_Of_Birth 
          type: 'text', 
          cssclass: 'datefield' 
         }, //Special_Needs_Physical 
         {}, //Special_Needs_Dietary 
         {}, //First_Name_For_Badge 
         {}, //Family_Name_For_Badge 
         {}, //Biography 
         {}, //VAT_Number 
         {}, //Membership_No 
         {}, //Participant_Template 
         { 
          tooltip: 'Click to select participant template', // Participant Template drop down 
          loadtext: 'Loading...', 
          data: '<?php print json_encode($template); ?>', 
          type: 'select', 
          submit: 'Ok' 
         }, 
         { 
          tooltip: 'Click to select a language', // Language Code drop down 
          loadtext: 'Loading...', 
          data: '<?php print json_encode($language); ?>', 
          type: 'select', 
          submit: 'Ok'         
         } //Language_Code 

     ] 

    }); 

我還沒有找到一個解決方案。我一直在搜索,大部分的帖子都是關於JSON中的空值的,所以我修改了aColumns並添加了這個sDefaultContent:「」來取代空值而不是空值。但我仍然得到同樣的錯誤。

回答

0

看來JSON出了問題。

我已將sDefaultContent:「」添加到aColumns中的每個列聲明中,並且現在錯誤消失了。

所以我aoColumns是這個樣子,現在

 "aoColumns": [ 
      { "mDataProp": "checkbox" ,"bSortable":false ,sDefaultContent:"", "sWidth" : "1%"}, 
      { "mDataProp": "Entity_Id" , "bSortable":true, "bVisible": false, sDefaultContent: "", "sWidth" : "1%" }, 
      { "mDataProp": "External_Id" ,"bSortable":true, sDefaultContent: "", "sWidth" : "1%" }, 
      { "mDataProp": "Family_Name" ,"bSortable":true, sDefaultContent: "", "sWidth" : "5%" }, 
      { "mDataProp": "First_Name" ,"bSortable":true, sDefaultContent: "", "sWidth" : "5%" }, 
      { "mDataProp": "Prefix_Title" ,"bSortable":true, sDefaultContent: "", "sWidth" : "1%" }, 
      { "mDataProp": "Suffix_Title" ,"bSortable":true, sDefaultContent: "", "sWidth" : "1%" }, 
      { "mDataProp": "Company" ,"bSortable":true, sDefaultContent: "", "sWidth" : "2%" }, 
      { "mDataProp": "Address_1" ,"bSortable":true, sDefaultContent: "", "sWidth" : "2%" }, 
      { "mDataProp": "Address_2" ,"bSortable":true, sDefaultContent: "", "sWidth" : "2%" }, 
      { "mDataProp": "Address_3" ,"bSortable":true, sDefaultContent: "", "sWidth" : "2%" }, 
      { "mDataProp": "Address_4" ,"bSortable":true, sDefaultContent: "", "sWidth" : "2%" }, 
      { "mDataProp": "Zip_Code" ,"bSortable":true, sDefaultContent: "", "sWidth" : "1%" }, 
      { "mDataProp": "City" ,"bSortable":true, sDefaultContent: "", "sWidth" : "2%" }, 
      { "mDataProp": "Country_Code" ,"bSortable":true, sDefaultContent: "", "sWidth" : "1%" }, 
      { "mDataProp": "Telephone" ,"bSortable":true, sDefaultContent: "", "sWidth" : "2%" }, 
      { "mDataProp": "Telefax" ,"bSortable":true, sDefaultContent: "", "sWidth" : "2%" }, 
      { "mDataProp": "EMail" ,"bSortable":true, sDefaultContent: "", "sWidth" : "2%" }, 
      { "mDataProp": "EMail2" ,"bSortable":true, sDefaultContent: "", "sWidth" : "2%" }, 
      { "mDataProp": "Session_Id" ,"bSortable":true, sDefaultContent: "", "bVisible": false, "sWidth" : "2%" }, 
      { "mDataProp": "Gender" ,"bSortable":true, sDefaultContent: "", "sWidth" : "1%" }, 
      { "mDataProp": "JMUser_Id" ,"bSortable":true, sDefaultContent: "", "bVisible": false, "sWidth" : "1%" }, 
      { "mDataProp": "Password" ,"bSortable":true, sDefaultContent: "", "bVisible": false, "sWidth" : "1%" }, 
      { "mDataProp": "ExtraField01" ,"bSortable":true, sDefaultContent: "", "bVisible": true, "sWidth" : "2%" }, 
      { "mDataProp": "ExtraField02" ,"bSortable":true, sDefaultContent: "", "bVisible": true, "sWidth" : "2%" }, 
      { "mDataProp": "ExtraField03" ,"bSortable":true, sDefaultContent: "", "bVisible": true, "sWidth" : "2%" }, 
      { "mDataProp": "ExtraField04" ,"bSortable":true, sDefaultContent: "", "bVisible": true, "sWidth" : "2%" }, 
      { "mDataProp": "ExtraField05" ,"bSortable":true, sDefaultContent: "", "bVisible": true, "sWidth" : "2%" }, 
      { "mDataProp": "ExtraField06" ,"bSortable":true, sDefaultContent: "", "bVisible": true, "sWidth" : "2%" }, 
      { "mDataProp": "ExtraField07" ,"bSortable":true, sDefaultContent: "", "bVisible": true, "sWidth" : "2%" }, 
      { "mDataProp": "ExtraField08" ,"bSortable":true, sDefaultContent: "", "bVisible": true, "sWidth" : "2%" }, 
      { "mDataProp": "ExtraField09" ,"bSortable":true, sDefaultContent: "", "bVisible": true, "sWidth" : "2%" }, 
      { "mDataProp": "ExtraField10" ,"bSortable":true, sDefaultContent: "", "bVisible": true, "sWidth" : "2%" }, 
      { "mDataProp": "Mobile" ,"bSortable":true, sDefaultContent: "", "bVisible": true, "sWidth" : "2%" }, 
      { "mDataProp": "URL" ,"bSortable":true, sDefaultContent: "", "bVisible": true, "sWidth" : "2%" }, 
      { "mDataProp": "Passport_Number" ,"bSortable":true, sDefaultContent: "", "bVisible": true, "sWidth" : "2%" }, 
      { "mDataProp": "Nationality" ,"bSortable":true, sDefaultContent: "", "bVisible": true, "sWidth" : "2%" }, 
      { "mDataProp": "ID_Number" ,"bSortable":true, sDefaultContent: "", "bVisible": true, "sWidth" : "2%" }, 
      { "mDataProp": "Date_Of_Birth" ,"bSortable":true, sDefaultContent: "", "bVisible": true, "sWidth" : "2%" }, 
      { "mDataProp": "Special_Needs_Physical" ,"bSortable":true, sDefaultContent: "", "bVisible": true, "sWidth" : "3%" }, 
      { "mDataProp": "Special_Needs_Dietary" ,"bSortable":true, sDefaultContent: "", "bVisible": true, "sWidth" : "3%" }, 
      { "mDataProp": "First_Name_For_Badge" ,"bSortable":true, sDefaultContent: "", "bVisible": true, "sWidth" : "5%" }, 
      { "mDataProp": "Family_Name_For_Badge" ,"bSortable":true, sDefaultContent: "", "bVisible": true, "sWidth" : "5%" }, 
      { "mDataProp": "Biography" ,"bSortable":true, "bVisible": true, sDefaultContent: "", "sWidth" : "2%" }, 
      { "mDataProp": "VAT_Number" ,"bSortable":true, "bVisible": true, sDefaultContent: "", "sWidth" : "2%" }, 
      { "mDataProp": "Membership_No" ,"bSortable":true, "bVisible": true, sDefaultContent: "", "sWidth" : "2%" }, 
      { "mDataProp": "Participant_Template" ,"bSortable":true, "bVisible": true, sDefaultContent: "", "sWidth" : "1%" }, 
      { "mDataProp": "Language_Code" ,"bSortable":true, "bVisible": true, sDefaultContent: "", "sWidth" : "1%" } 
      ], 

所有排序!