2012-07-26 7 views
0

Datatables 플러그인 (http://www.datatables.net)과 Datatables Editor (http://editor.datatables.net)를 사용하여 일부 테이블 설정이 있습니다.Datatables - 기존 테이블에 편집기 통합

편집기를 기존 테이블에 통합하려고하지만 모든 편집 필드 (팝업)에서 정의되지 않은 상태가됩니다.

내가 가진 것과 발전기 다운로드 사이에 유일한 차이점은 aoColumns 설정입니다.

"aoColumns": [ 
{ "sTitle": "id" }, 
{ "sTitle": "Name" }, 
{ "sTitle": "Surname" }, 
{ "sTitle": "Email" } 

하지만 편집기 코드가 있습니다 :

이 내가 현재 가지고있는 것입니다

"aoColumns": [ 
{ "mDataProp": "id" }, 
{ "mDataProp": "Name" }, 
{ "mDataProp": "Surname" }, 
{ "mDataProp": "Email" } 

나는 "sTitle"에서 "mDataProp"내 테이블에 더 이상 부하를 변경할 때.

분명히 잘못된 방향으로 가고 있습니다 ... 이에 대한 방향은 매우 높이 평가 될 것입니다.

편집 :

여기

내 전체 코드입니다 :

<script type="text/javascript"> 
    function fnShowHide(iCol){ 
     /* Get the DataTables object again - this is not a recreation, just a get of the object */ 
     var oTable = jQuery('#example').dataTable(); 

     var bVis = oTable.fnSettings().aoColumns[iCol].bVisible; 
     oTable.fnSetColumnVis(iCol, bVis ? false : true); 
    } 

    (function($){ 

    $(document).ready(function() { 

    var aDataSet = [ 
      var aDataSet = [ 
['805', 
'Emelia', 
'Smith', 
'[email protected]' 
], 
['804', 
'david', 
'Davies', 
'[email protected]' 
],  
    ]; 
        var editor = new $.fn.dataTable.Editor({ 
         "ajaxUrl": "php/table.wp_newsletter.php", 
         "domTable": "#example", 
         "fields": [ 
       { 
        "label": "First Name", 
        "name": "name", 
        "type": "text" 
       }, 
       { 
        "label": "Last Name", 
        "name": "surname", 
        "type": "text" 
       }, 
       { 
        "label": "Email Address", 
        "name": "email", 
        "type": "text" 
       } 
      ] 
        }); 
        var oTable;    
        var oTable = $('#example').dataTable({ 
         "sDom": '<"postbox full"<W>><"clear"><"postbox full"<C><T>><"clear"><"postbox full"<lfr>><"clear"><"postbox full"<t>>ip', 
         "oColumnFilterWidgets": { 
          "aiExclude": [ 0,1,2,3,6,7,9 ], 
         }, 
         "iDisplayLength": 50, 
         "sPaginationType": "full_numbers", 
         "bSortClasses": false, 
         "aaData": aDataSet, 
         "oLanguage": { 
          "sSearch": "Search all columns:" 
         }, 
         "oTableTools": { 
         "sSwfPath": "swf/copy_csv_xls_pdf.swf", 
         "sRowSelect": "multi", 
         "aButtons": [ 
          { "sExtends": "editor_create", "editor": editor }, 
          { "sExtends": "editor_edit", "editor": editor }, 
          { "sExtends": "editor_remove", "editor": editor } 
         ] 
         }, 
         "aoColumns": [ 
          { "sTitle": "id" }, 
          { "sTitle": "Name" }, 
          { "sTitle": "Surname" }, 
          { "sTitle": "Email" }, 
          { 
           "sTitle": "Admin", 
           "sClass": "center", 
           "sDefaultContent": '<a href="" class="editor_edit">Edit</a>/<a href="" class="editor_remove">Delete</a>' 
          } 
         ], 
        }); 

        oTable.fnSetColumnVis(7, false); 
        oTable.fnSetColumnVis(8, false); 
        oTable.fnSetColumnVis(9, false); 

        // New record 
        $('a.editor_create').on('click', function (e) { 
         e.preventDefault(); 

         editor.create(
          'Create new record', 
          { "label": "Add", "fn": function() { editor.submit() } } 
         ); 
        }); 

        // Edit record 
        $('#example').on('click', 'a.editor_edit', function (e) { 
         e.preventDefault(); 

         editor.edit(
          $(this).parents('tr')[0], 
          'Edit record', 
          { "label": "Update", "fn": function() { editor.submit() } } 
         ); 
        }); 

        // Delete a record (without asking a user for confirmation) 
        $('#example').on('click', 'a.editor_remove', function (e) { 
         e.preventDefault(); 

         editor.remove($(this).parents('tr')[0], '123', false, false); 
         editor.submit(); 
        }); 

        var asInitVals = new Array(); 

        $("#filter input").keyup(function() { 
         /* Filter on the column (the index) of this element */ 
         oTable.fnFilter(this.value, $("#filter input").index(this)+1); 
         //console.log($("#filter input").index(this)+1); 
        }); 
        /* 
        * Support functions to provide a little bit of 'user friendlyness' to the textboxes in 
        * the footer 
        */ 
        $("#filter input").each(function (i) { 
         asInitVals[i] = this.value; 
        }); 

        $("#filter input").focus(function() { 
         if (this.className == "search_init") 
         { 
          this.className = ""; 
          this.value = ""; 
         } 
        }); 

        $("#filter input").blur(function (i) { 
         if (this.value == "") 
         { 
          this.className = "search_init"; 
          this.value = asInitVals[$("#filter input").index(this)]; 
         } 
        }); 

    }); 

    }(jQuery)); 


     </script> 
+0

당신은 너무 친절하고 초기 Initializatio 전체를 추가 할 수 있습니까? 질문에 n 코드? 또한이 함수'$ .fn.dataTable.Editor()'를 질문에 추가하여 가능한 모든 오류를 검사 할 수 있습니까? – Drakkainen

+0

편집 됨 .. thsanks @Iro. – Cybercampbell

답변

0

시도가 변경 :

"aoColumns": [ 
    { "mDataProp": "id" }, 
    { "mDataProp": "Name" }, 
    { "mDataProp": "Surname" }, 
    { "mDataProp": "Email" } 

"aoColumns": [ 
{ "sTitle": "id" }, 
{ "mDataProp": "name", "sTitle": "Name" }, 
{ "mDataProp": "surname", "sTitle": "Surname" }, 
{ "mDataProp": "email", "sTitle": "Email" } 

에 나는 경험에서 알고 datatables/jvascript 케이스 센이다 그래서 그것은 mDataProp의 문제 일 수 있습니다.

변경이 :

"fields": [ 
      { 
       "label": "First Name", 
       "name": "name", 
       "type": "text" 
      }, 
      { 
       "label": "Last Name", 
       "name": "surname", 
       "type": "text" 
      }, 
      { 
       "label": "Email Address", 
       "name": "email", 
       "type": "text" 
      } 

사람 :

"aoColumns": [ 
{ "mDataProp": "id", "sTitle": "id" }, 
{ "mDataProp": "name", "sTitle": "Name" }, 
{ "mDataProp": "surname", "sTitle": "Surname" }, 
{ "mDataProp": "email", "sTitle": "Email" } 
: 다음

"fields": [ 
      { 
       "label": "ID", 
       "name": "id", 
       "type": "text" 
      }, 
      { 
       "label": "First Name", 
       "name": "name", 
       "type": "text" 
      }, 
      { 
       "label": "Last Name", 
       "name": "surname", 
       "type": "text" 
      }, 
      { 
       "label": "Email Address", 
       "name": "email", 
       "type": "text" 
      } 

그리고이 업데이트

UPDATE가 D : 그게 아니라면, 우리는 더 깊은 검색 갈 수 있습니다

+0

감사합니다. 경고 : DataTables warning (table id = 'example') : 행 0의 데이터 소스에서 알 수없는 매개 변수 'name'을 요청했습니다. – Cybercampbell

+0

@cybercampbell 업데이트 : – Drakkainen

+0

Thanks @Iro. 동일한 오류 메시지가 표시되고 테이블이 비어 있습니다. 이견있는 사람? – Cybercampbell