4

私はjquery-2.0.3.min.js、bootstrap.min.js、jquery-ui-1.10.3.min.js、DataTables-1.9.4をtabletools、datatables.net/blog/Twitter_Bootstrap_2で使用しています

私の見解

  <div id="windowDepartment" title="Departments"></div>


 <table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered table-hover table-condensed" id="DepartmentTable">
        <thead>
            <tr>
                <th>departmentID</th>
                <th>departmentName</th>
                <th>description</th>
                <th>Action</th>
            </tr>
        </thead>
        <tbody>
        </tbody>
    </table>

データテーブル初期化スクリプト

    $(document).ready(function () {
    oDepartmentTable = $('#DepartmentTable').dataTable(
            {

                "sDom": "T<'clear'>lfrtip",
                "bJQueryUI": true,
                "sPaginationType": "full_numbers",
                "bServerSide": true,
                "sAjaxSource": "Department/AjaxList",
                "aaSorting": [[2, 'asc'], [3, 'asc']],
                "aoColumns": [
                                { "mDataProp": "departmentID", "sType": "string", "bVisible": false, "bSearchable": false },
                                { "mDataProp": "departmentName", "sType": "string", "bVisible": true, "bSearchable": true },
                                { "mDataProp": "description", "sType": "string", "bVisible": true, "bSearchable": true },
                                { "mDataProp": null,"bSearchable": false,
                                 "sDefaultContent": '<div class="btn-group"><a class="btn btn-mini dropdown-toggle" data-toggle="dropdown" href="#"><span class="icon-circle-arrow-down"></span></a><ul class="dropdown-menu"><li><a class="editDepartment"> <i class="icon-pencil"></i> Edit</a></li><li><a class="deleteDepartment"> <i class="icon-trash"></i> Delete</a></li></ul></div>'
                                }
                            ],

                "oTableTools": {
                    "sSwfPath": "/Content/DataTables-1.9.4/extras/TableTools/media/swf/copy_csv_xls_pdf.swf"
                }

            });

        });

フォーム スクリプトの編集

       $(document).ready(function () {
            $('#DepartmentTable tbody').on('click', 'a.editDepartment', function (e) {
                e.preventDefault();

                //1. Dose not work shows "not available"
                var aData = oDepartmentTable.fnGetData(this)

                //2. Gets the correct ID if "bVisilble=true"
                var departmentid = $(this).parent().parent().parent().parent().parent().children()[0].innerHTML ;

                //goto Edit Controller. DepartmentID is required here  
                $.get('Department/Edit/' + departmentid , function (data) {
                    $('div#windowDepartment').html(data);

                    //Open Dialog box 
                    $("#windowDepartment").dialog().dialog({
                        resizable: true,
                        height: 500,
                        width: 500,
                        modal: true,
                        buttons:
                    {
                        Edit: function () {
                            editDepartment();   //Saves the data. Works fine
                        }, // end ok button

                        Cancel: function () {
                            $(this).dialog("close");
                        }
                    },  //end buttons
                        close: function () {
                            $(this).dialog("close");
                        }
                    }); //end modal edit
                });
            });
        });

私の問題。(EDIT FORM SCRIPT 内)

コントローラーに渡す DepartmentID が必要です ('Department/Edit/' + departmentid)

私の観察 1) var aData = oDepartmentTable.fnGetData(this) Chrome コンソールでは常に「利用できません」と表示されます。

2) var departmentid =$(this).parent().parent().parent().parent().parent().children()[0].innerHTML データテーブルの初期化で "bVisible": true を使用すると、正しい departmentID が取得されます。

(3) 部門 ID をエンド ユーザーに表示したくありません。データテーブルの初期化で "bVisible": false を作成した場合

var departmentid = $(this).parent().parent().parent().parent().parent().children()[0].innerHTML 部門名を返します

ありがとう

4

1 に答える 1

3

ここのdatatablesフォーラムとfnGetPositionでの議論を見てください

代わりにこのクリックハンドラを試してください:

$(document).ready(function () {
    $('#DepartmentTable tbody tr').on('click', function (e) {

        // get the position of the current data from the node
        var aPos = oDepartmentTable.fnGetPosition( this );

        // get the data array
        var aData = oDepartmentTable.fnGetData( aPos[0] );

        // get departmentID for the row
        var departmentID = aData[aPos].departmentID;
        console.log(departmentID);

        // ... do your stuff here, eg
        //goto Edit Controller. DepartmentID is required here  
        //$.get('Department/Edit/' + departmentid , function (data) {
        //..
        //..
    });
});

わたしにはできる。ただし、ドキュメントが言うほどではありません。また、最初に datatables 1.9.1 を試してみましたが、まったく機能しませんでした。データテーブルのこの領域にはいくつかのバグがあり、バージョンごとにリファクタリングされていると思います。

于 2013-08-08T11:30:06.810 に答える