0

JQuery Datatables で Codeigniter を使用して、MYSQL データベースのデータを AJAX/JSON リクエストを介してリアルタイムで更新しています。私はこのコードの元の開発者ではないため、この問題を解決できないと思います。

私が持っているのは 26 列のテーブルです。すべての列がまだ入力されているわけではありませんが、すべてがデータベースから直接存在しているようです。json_table 関数のコードの一部は次のようになります。

$this->load->model('aircraft_model');
$this->load->model('nats_model');

$aColumns = array('FlightSts', 'TblOrder', 'Callsign', 'Destination', 'NAT', 'SELCAL', 'CldFL', 'CldMach', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 'FlightID');
$sTable = 'naecs_aircraft';

$stable は、正しい mysql テーブルのようです。$acolumns は、mysql テーブル naecs_aircraft のすべてのフィールドのようです。それはすべて正しく、機能しますが、最後の 2 番目の列で、FlightID の直前にボタンを設定したいと考えています。基本的に、最後から2番目の列にボタンが必要です。

どうやってするの?

よろしく、マチェイ。

@編集1

これは、コントローラー ajax.php 内の関数全体です。

public function json_table(){
    $this->access->requires(ACCESS_USER);
    $this->load->model('aircraft_model');
    $this->load->model('nats_model');

    $aColumns = array('FlightSts', 'TblOrder', 'Callsign', 'Destination', 'NAT', 'SELCAL', 'CldFL', 'CldMach', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 'FlightID');
    $sTable = 'naecs_aircraft';

    $iDisplayStart = $this->input->get_post('iDisplayStart', true);
    $iDisplayLength = $this->input->get_post('iDisplayLength', true);
    $iSortCol_0 = $this->input->get_post('iSortCol_0', true);
    $iSortingCols = $this->input->get_post('iSortingCols', true);
    $sSearch = $this->input->get_post('sSearch', true);
    $sEcho = $this->input->get_post('sEcho', true);

    if(isset($iSortCol_0))
    {
        for($i=0; $i<intval($iSortingCols); $i++)
        {
            $iSortCol = $this->input->get_post('iSortCol_'.$i, true);
            $bSortable = $this->input->get_post('bSortable_'.intval($iSortCol), true);
            $sSortDir = $this->input->get_post('sSortDir_'.$i, true);

            if($bSortable == 'true')
            {
                if ($aColumns[$iSortCol] != ' '){
                    $this->aircraft_model->json_table_sort($aColumns, $iSortCol, $sSortDir);
                }
            }
        }
    }

    if(isset($sSearch) && !empty($sSearch))
    {
        for($i=0; $i<count($aColumns); $i++)
        {
            if ($aColumns[$i] != ' '){
                $bSearchable = $this->input->get_post('bSearchable_'.$i, true);
                if(isset($bSearchable) && $bSearchable == 'true')
                {
                    $this->aircraft_model->json_table_filter($aColumns, $i, $sSearch);
                }
            }
        }
    }

    $rResult = $this->aircraft_model->json_table_select($aColumns, $sTable);
    $iFilteredTotal = $this->aircraft_model->json_table_found($aColumns);
    $iTotal = $this->aircraft_model->count_all($sTable);

    $output = array(
        'sEcho' => intval($sEcho),
        'iTotalRecords' => $iTotal,
        'iTotalDisplayRecords' => $iFilteredTotal,
        'aaData' => array()
    );

    $headers = array('3active' => FALSE, '2cleared' => FALSE, '4closed' => FALSE, '1entered' => FALSE, '5disconnected' => FALSE);

    foreach($rResult->result_array() as $aRow)
    {
        $row = array();

        foreach($aColumns as $col)
        {
            @$row[] = $aRow[$col];
        }

        $databit = $row;
        $databit['DT_RowId'] = $aRow['FlightID'];
        $databit['DT_RowName'] = $aRow['Callsign'];
        $output['aaData'][] = $databit;
        $headers[$aRow['FlightSts']] = TRUE;
    }

    foreach ($headers as $key => $value){
        if ($value == FALSE){
            $output['aaData'][] = array($key, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ');
        }
    }

    $output['aaData'][] = array('No More Aircraft', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ');

    echo json_encode($output);
}

tableinit.js:

function initTable(){
    oTable = $('#main-table').dataTable({
        "bProcessing": true,
        "bServerSide": true,
        "bSort": true,
        "sServerMethod": "GET",
        "sAjaxSource": "ajax/json_table",
        "oLanguage": { "sProcessing": "<i class='icon-refresh icon-spin'></i>" },
        "sDom": "<'pull-right'r><'row'<'span8'l>>tS",
        "sScrollY": "400px",
        "bPaginate": false,
        "bScrollCollapse": true,
        "aoColumnDefs": [ 
        { "bVisible": false,  "aTargets": [ 1, 25 ] },
        ],
        "aaSorting": [[ 1, "asc" ]],
        "fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
            $('td:eq(0)', nRow).attr("name", "callsign");
            $('td:eq(1)', nRow).attr("name", "destination");
            $('td:eq(2)', nRow).attr("name", "nat");
            $('td:eq(3)', nRow).attr("name", "selcal");
            $('td:eq(4)', nRow).attr("name", "lvl");
            $('td:eq(5)', nRow).attr("name", "mach");
        },
    }).rowGrouping({ iGroupingColumnIndex: 0, sGroupingClass: 'nodrop', bSetGroupingClassOnTR: true });
}
4

2 に答える 2

0

私はあちこちで調査しましたが、最終的に解決策を得ました。

foreach($aColumns as $col)
{
        @$row[] = $aRow[$col];
}

私はちょうど追加しました:

$row[24] = '<a data-toggle="modal" href=#clrAircraft" data target="#clrAircraft">Clearance</a>';

非常に簡単な解決策です。これにより、aColumns 配列から列 24 が取り出されるため、テーブルの列 25 に追加するものをすべて追加します。

于 2013-05-20T02:18:34.153 に答える