i want to create a table in the datatables which does not have data in the last rows data. i wanna leave it empty with borders. right now i when i 10 rows of data 4on each page. the data get into 3pages where first and second page have 4 rows and when we reach the third page there is only two data and the other space is left blank. i wanna create a table and then fetch data but the datatable is creating the table in my code so. cud anyone suggest how can i leave the last two rows blank and visible.
var dataSet = [];
for(var i = 0; i < data.response.docs.length; i++)
{
var d = data.response.docs[i];
var minPrice = d.min_price;
var minPrice = d.shipping;
var seller_rating = d.rating;
var product_rating = d.product_rating;
var total = minPrice + shipping;
var ships_on = 'n/a';
var delivered_by = 'n/a';
dataSet.push([{ 'url': d.url},
total,
minPrice + '+' + shipping,
ships_on, delivered_by,
seller_rating, product_rating]);
}
$('#data_table').dataTable( {
"aaData": dataSet,
"aaSorting": [[0,'asc'],[0,'desc'],[2,'asc'],[2,'desc'],[3,'asc'],[3,'desc'],[4,'asc'],[4,'desc'],[5,'asc'],[5,'desc'],[6,'asc'],[6,'desc'],[7,'asc'],[7,'desc']],
"iDisplayLength": 4,
"bInfo": true,
"bLengthChange": false,
"bJQueryUI": true,
"bPaginate": true,
"bAutoWidth": false,
"sPaginationType": 开发者_高级运维"full_numbers",
"bAutoWidth": true,
"aoColumns": [
{ "sTitle": "Seller",
"sWidth": "155px",
"sClass": "grey" ,
"fnRender": function(obj) {
var data = obj.aData[ obj.iDataColumn ];
return "<A href='"+ data.url +"'>"+ data.title +"</A>";
}
},//, "sWidth": "130px"
{"sTitle": "Item Matched","sWidth": "100px","sClass":"center yellow","bSortable": false,
"fnRender": function (obj) {
//var img = obj.aData[obj.iDataColumn];
var data = obj.aData[obj.iDataColumn];
return "<img width='90px' height='50px' src='" + data.image + "'/><br>"+ data.name.slice(0,25);
}
},
{ "sTitle": "Total Price(in $)","sClass": "center grey" },
{ "sTitle": "Price + Shipping(in $)","sClass": "center yellow" },
{ "sTitle": "Ships On", "sClass": "center grey" },
{ "sTitle": "Delivered By","sClass": "center yellow" },
{
"sTitle": "Seller rating",
"sClass": "center grey",
"fnRender": function(obj) {
var sReturn = obj.aData[ obj.iDataColumn ];
var val = obj.aData[ obj.iDataColumn ];
if ( sReturn != "N/A") {
$('#fixed').raty({
readOnly: true,
start: val
});
sReturn = $('#fixed').html();
$('#fixed').html("");
}
return sReturn;
}
},
});
I just want the last two rows to be visible wheater they have data or not
if(dataSet != '' || no/4 != 0)
{
//alert(no);
var minPrice = 0;
var shipping = 0;
var seller_rating = 0;
var product_rating = 0;
var ships_on = 'n/a';
var delivered_by = 'n/a';
var total = minPrice + shipping;
var a = no%4;
for(var i=0;i<(4-a);i++)
{
dataSet.push([{'title': '', 'url': ''},
{'image': '', 'name': ''},
'0',
'0',
'n/a', 'n/a',
'0', '0']);
}
}
$('#data_table').dataTable( {
"aaData": dataSet ,
"bSort":true,
"aaSorting": [[0,'desc'],[0,'asc'],[2,'asc'],[2,'desc'],[3,'asc'],[3,'desc'],[4,'asc'],[4,'desc'],[5,'asc'],[5,'desc'],[6,'asc'],[6,'desc'],[7,'asc'],[7,'desc']],
"iDisplayLength": 4,
"bInfo": true,
"bLengthChange": false,
"bJQueryUI": true,
"bPaginate": true,
"bAutoWidth": false,
"sPaginationType": "full_numbers",
"bAutoWidth": true,
"aoColumns": [
{ "sTitle": "Seller",
"sWidth": "155px",
"sClass": "grey" ,
"fnRender": function(obj) {
var data = obj.aData[ obj.iDataColumn ];
return "<a href='"+ data.url +"'>"+ data.title +"</a>";
}
}
Its creating two rows which is not having data and is empty. and will create two empty row. I needed data where in each page thereare 4 data in each page. so i m using it in mutiples of 4.
I don't know about the datatable plugin you have been using however you can pad your dataset with empty values to make it work:
var dataset = ['1','2','3','4','5','6','7','8','9'];
var rowCount = 4;
var mod = dataset.length%rowCount;
if(mod) {
for(var i=mod; i<rowCount;i++) {
dataset.push('')
}
}
http://jsfiddle.net/bsrykt/JJtNN/
精彩评论