Datatables - Search Box outside datatable

前端 未结 11 1350
攒了一身酷
攒了一身酷 2020-11-30 17:08

I\'m using DataTables (datatables.net) and I would like my search box to be outside of the table (for example in my header div).

Is this possible ?

11条回答
  •  不知归路
    2020-11-30 17:35

    $('#example').DataTable({
       "bProcessing": true,
       "bServerSide": true,
       "sAjaxSource": "../admin/ajax/loadtransajax.php",
       "fnServerParams": function (aoData) {
            // Initialize your variables here
            // I have assign the textbox value for "text_min_val"
            var min_val = $("#min").val();  //push to the aoData
            aoData.push({name: "text_min_val", value:min_val});
       },
       "fnCreatedRow": function (nRow, aData, iDataIndex) {
           $(nRow).attr('id', 'tr_' + aData[0]);
           $(nRow).attr('name', 'tr_' + aData[0]);
           $(nRow).attr('min', 'tr_' + aData[0]); 
           $(nRow).attr('max', 'tr_' + aData[0]); 
       }
    });
    

    In loadtransajax.php you may receive the get value:

    if ($_GET['text_min_val']){
        $sWhere = "WHERE ("; 
        $sWhere .= " t_group_no LIKE '%" . mysql_real_escape_string($_GET['text_min_val']) . "%' ";
        $sWhere .= ')';
    }
    

提交回复
热议问题