ajax行可编辑数据表

时间:2013-03-05 07:47:00

标签: php javascript jquery html ajax

当我点击编辑按钮时,我正在尝试弹出{ "bSortable": false, "fnRender": function(oObj){return "<a href='main.php?do=labour&action=edit&sid=" + oObj.aData[12] + "'>Edit</a>"; } }

这是我的gui

gui

这是我的代码:

    <script type="text/javascript" charset="utf-8">
        var oTable;

        /* Formating function for row details */
        function fnFormatDetails ( nTr )
        {
            var aData = oTable.fnGetData( nTr );
            var sOut = '<table cellpadding="5" cellspacing="0" border="0" style="padding-left:50px;">';
            sOut += '<tr><td>Name:</td><td style="color:blue;">'+aData[3]+' '+aData[4]+' '+aData[5]+'</td></tr>';
            sOut += '<tr><td>Tag ID:</td><td style="color:blue;">'+aData[1]+'</td></tr>';
            sOut += '<tr><td>ID #:</td><td style="color:blue;">'+aData[2]+'</td></tr>';
            sOut += '<tr><td>Course:</td><td style="color:blue;">'+aData[9]+'</td></tr>';
            sOut += '<tr><td>Department:</td><td style="color:blue;">'+aData[7]+'</td></tr>';
            sOut += '<tr><td>Contact:</td><td style="color:blue;">'+aData[8]+'</td></tr>';
            sOut += '<tr><td>Address:</td><td style="color:blue;">'+aData[9]+'</td></tr>';
            sOut += '<tr><td>Last Modified:</td><td style="color:blue;">'+aData[10]+'</td></tr>';
            sOut += '</table>';

            return sOut;
        }
        $(document).ready(function() {
            oTable = $('#example').dataTable( {
                "bProcessing": true,
                "bServerSide": true,
                "sAjaxSource": "scripts/server_processing.php",
                "aoColumns": [
                    { "sClass": "", "bSortable": false },
                    null,
                    null,
                    null,
                    { "sClass": "" },
                    { "sClass": "" },
                    { "bSortable": false, "fnRender":  function(oObj){return "<a href='main.php?do=labour&action=edit&sid=" + oObj.aData[12] + "'>Edit</a>"; } //heres is my problem }

                ],
                "aaSorting": [[1, 'asc']]
            } );

            $('#example tbody td img').live( 'click', function () {
                var nTr = $(this).parents('tr')[0];
                if ( oTable.fnIsOpen(nTr) )
                {
                    /* This row is already open - close it */
                    this.src = "examples_support/details_open.png";
                    oTable.fnClose( nTr );
                }
                else
                {
                    /* Open this row */
                    this.src = "examples_support/details_close.png";
                    oTable.fnOpen( nTr, fnFormatDetails(nTr), 'details' );
                }

            } );

        } );

    </script>

帮助我的代码从MySQL数据库动态显示jQuery弹出窗口。弹出窗口显示所有行但不显示相同的id,即正确的id没有传递给弹出窗口。任何人都可以建议我。

1 个答案:

答案 0 :(得分:1)

  { "bSortable": false, "fnRender":  function(oObj){return "<a href='main.php?do=labour&action=edit&sid=" + oObj.aData[12] + "'>Edit</a>"; } 

不应该是oObj.aData [2]而不是oObj.aData [12]吗?