由于某些原因,我使用了服务器端数据表,我试图显示其中一个列的评级星,所有数据都正确显示,
这是我的.js代码
$(document).ready(function(){
table = $('.dataTables-example').DataTable({
"serverSide": true,
"ajax": {
"url": "<?php echo base_url('admin/Review/get_Data')?>",
"type": "POST"
},
"columns": [
{ "data": "review_id", "name":"review_id"},
{ "data": "hotel_name", "name":"hotel_name"},
{ "data": "review_by", "name":"review_by"},
{ "data": "review_title", "name":"review_title"},
{ "data": "review_desc",
"render":function(data, type, row){
var review = row.review_desc;
var id = row.review_id;
if(row.review_desc.length > 50) {
var desc = '<div class="showbox">'+review.substring(0, 50)+'</div><span class="'+id+'more" style="display:none;">'+review.substring(50)+'</span><br><span onclick="see_more('+id+')" class="'+id+'readmore" style="color:red; cursor:pointer;">See More</span><span class="'+id+'nomore" onclick="nomore('+id+')" style="color:red;display:none; cursor:pointer;">See Less</span>';
}
else{
var desc = review;
};
return desc;
},searchable: false, sortable: false
},
{ "data": "created_at",
render: function(created_at){
return moment(created_at).format("DD/MM/YYYY HH:mm A");
}
},
{ "data": "rating_star",
render: function(rating_star){
return '<div class="star_rating_customer_reviews"><input value="'+rating_star+'" type="number" class="rating" min=0 max=5 step=0.1 data-size="sm" data-stars="5" href="#" readonly="true"></div>';
}, searchable: false, sortable: false
}
],
"order": [ 0, 'desc' ],
"columnDefs": [
{
"targets": [ 0 ],
"visible": false,
"searchable": false
}
]
});
});
在这里,我正在尝试从列 rating_star 外部评级css中显示评级星,并且js未应用于此并且显示为,
查看它显示输入字段的raings列, 我已经在html中完成了,
<div class="star_rating_customer_reviews"><input value="1" type="number" class="rating" min=0 max=5 step=0.1 data-size="sm" data-stars="5" href="#" readonly="true"></div>
它完全显示在选择的记录数上方以显示下拉列表。看起来外部脚本无法从datatable列访问。 我陷入了困境,
{ "data": "rating_star",
render: function(rating_star){
return '<div class="star_rating_customer_reviews"><input value="'+rating_star+'" type="number" class="rating" min=0 max=5 step=0.1 data-size="sm" data-stars="5" href="#" readonly="true"></div>';
}, searchable: false, sortable: false
}
请帮帮我, 使用了ajax数据表: - datatables.net
我使用的评级插件是: - star rating
答案 0 :(得分:2)
您可以尝试这样的事情:
columns:..,
order: ...,
createdRow: function (row, data, dataIndex) {
// any manipulation in the row element
var ratingInput = $(row).find('.rating');
$(ratingInput).rating();
}