显示来自 Data-table 列渲染的评级星不起作用
Displaying Rating star from Data-table column render is not working
出于某些原因,我使用了服务器端数据表,我正在尝试显示其中一列的评级星级,所有数据都正确显示,
Here is my .js code
$(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>
它完美地显示在 select 记录数之上以显示下拉列表。看起来外部脚本没有从数据表列访问。
我被困在这个,
{ "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
您可以尝试这样的操作:
columns:..,
order: ...,
createdRow: function (row, data, dataIndex) {
// any manipulation in the row element
var ratingInput = $(row).find('.rating');
$(ratingInput).rating();
}
出于某些原因,我使用了服务器端数据表,我正在尝试显示其中一列的评级星级,所有数据都正确显示,
Here is my .js code
$(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>
它完美地显示在 select 记录数之上以显示下拉列表。看起来外部脚本没有从数据表列访问。 我被困在这个,
{ "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
您可以尝试这样的操作:
columns:..,
order: ...,
createdRow: function (row, data, dataIndex) {
// any manipulation in the row element
var ratingInput = $(row).find('.rating');
$(ratingInput).rating();
}