php中tables,填充PHP数据的datatables子表

所以我希望将来有其他人会有同样的问题.下面的代码是大约25个不同帖子的结果,这些帖子在数据表网站上有很多和很多阅读.我最终能够完成我原本想做的所有事情 – 它只是让我永远研究如何做到这一点!这是我解决它的方式:

首先,我对databaseSearch.php的查询:

$searchQuery = "SELECT * FROM alldata where $searchBy like '%$searchValue%' LIMIT 400" ; //limiting helps with that memory overflow error in my original question

mysqli_set_charset($con, 'utf8');

$searchResult = mysqli_query($con, $searchQuery);

然后,从带回的数据中创建一个数组:

while ($row = mysqli_fetch_row($searchResult)) {

$item = array();

$item["id"] = $row[0];

$item["dateReceived"] = $row[1];

$item["comments"] = $row[2];

$output[] = $item;

}

$out = array('aaData' => $output);

echo json_encode($out);

然后,整个数据表代码:

function format ( d ) {

// `d` is the original data object for the row

return '

'+

'

//creating a submit button inside the dropdown that uses HTML5 datasets, i can pass ALL the information from `d` to one button, so I can pass it all off to another page.

'

'+

'

'+ //and I can make new s and s using this syntax:

'

cost'+

'

'+d.cost+''+

'

resale'+

'

'+d.resale+''+

'

'+

'

'+

'

Date Received'+

'

'+d.dateReceived+''+

'

Name'+

'

'+d.name+''+

'

'+

'

'+

'

';

}

$.fn.dataTable.ext.errMode = 'throw'; //shows errors in console

var table = $('#table').DataTable( {

ajax : {

url : 'databaseSearch.php' ,

dataSrc : 'aaData' ,

type : 'POST',

data: {searchBy:searchBy, searchValue:searchValue, options:options},

},

//the "createdRow" function allows me to do additional things with the rows I output.

"createdRow" : function (row,data,index) {

$('td',row).eq(0).attr('id', 'customer-' + index); //like create an id

$('td',row).eq(1).attr('id', 'location-' + index);

$('td',row).eq(2).attr('id', 'zip-' + index);

$('td',row).eq(3).attr('id', 'projectName-' + index);

$('td',row).eq(3).attr('id', 'zDate-' + index);

$('td',row).eq(7).attr('id', 'ID-' + index);

//This sections handles the icons that are placed in the first cell

//This adds either a valid or invalid flag to the first cell

if ( data["zDate"]) {

SelectedDate = new Date(data["zDate"]);

if (SelectedDate > CurrentDate) {

zImage = $('').attr('src', '../../img/valid.png');

$('td',row).eq(0).append(zImage);

//adding this class allows me to absolutely position the debit image for each line.

$('td',row).eq(0).addClass( 'icons' ); //or add classes...

} else {

zImage = $('').attr('src', '../../img/invalid.png');

$('td',row).eq(0).append(zImage); //or apply images...

$('td',row).eq(0).addClass( 'icons' );

}

}

},

// "columns" is the top level

s that will be created.

columns : [

//{ className : 'details-control'},

{ data : 'customer' },

{ data : 'location' },

{ data : 'zip' },

{ data : 'projectName' },

{ data : 'ID' },

],

"columnDefs": [

{ className: "details-control", "targets": [ 0 ] }

],

"lengthMenu": [ 25, 50, 101 ],

"oLanguage": {

"sSearch": "Filter Results: "

}

});

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值