我使用Google表格。 当我按照img 1中的数字从10到99对它进行排序时,它的排序很好。
--- IMG 1 ----
但是,当我使用一个数字1-9或超过100时,它不能很好地排序,就像你在img 2中看到的那样。
---- IMG 2 ----
我该如何解决问题?
我使用以下代码。
<script type='text/javascript'>
google.load('visualization', '1', {packages:['table']});
google.setOnLoadCallback(drawTable);
function drawTable() {
var data = new google.visualization.DataTable();
data.addColumn('string', 'ID');
data.addColumn('string', 'Name');
data.addColumn('string', 'Image');
data.addColumn('string', 'Image Size');
data.addColumn('string', 'Order');
data.addColumn('string', 'Status');
data.addColumn('string', 'Actions');
data.addRows([
<?php
if (count($slideshow))
{
foreach($slideshow as $item)
{
$namelink = anchor("$module/admin/edit/".$item['id'],$item['name']);
$subject = $item['image'];
$imagename = getImageName($subject);
$imagepath = getImagePath($subject);
$filepath = base_url().$imagepath;
$imagecont = "<img width=\"70px\" src=\'".$filepath."\' />";
$filesize = getimagesize($imagepath);
$filesizecont = "width: ".$filesize[0]. "px<br />height: ".$filesize[1]. "px";
$item = str_replace("'", "\'", $item);
/* $public_icon = ($item['public']==1 ? 'tick':'cross'); */
/* $publiclink = anchor("kaimonokago/admin/changecatBooleanStatus/$module/".$item['id']."/public",$this->bep_assets->icon($public_icon), array('class' => $item['public']. ' changestatus')); */
$active_icon = ($item['status']=='active'?'tick':'cross');
$statuslink = anchor("kaimonokago/admin/changeStatus/$module/".$item['id'],$this->bep_assets->icon($active_icon), array('class' => $item['status']. ' changestatus'));
$editlink = anchor($module.'/admin/edit/'.$item['id'],$this->bep_assets->icon('pencil'));
if ($item['status']=='inactive')
{
$deletelink = anchor('kaimonokago/admin/delete/'.$module.'/'.$item['id'],$this->bep_assets->icon('delete'), array("class" => "delete_link","onclick"=>"return confirmSubmit(\'".$item['name']."\')"));
}
else
{
$deletelink ='';
}
//$link = "testing";
echo "['".$item['id']."','".$namelink."','".$imagecont."','".$filesizecont."','".$item['slide_order']."','".$statuslink."','".$editlink.$deletelink."' ],\n";
}
}
?>
]);
var table = new google.visualization.Table(document.getElementById('table_div'));
table.draw(data, {showRowNumber: true, allowHtml:true,width:'100%'});
}
</script>
<div id='table_div'></div>
<script>
$(window).resize(function(){
drawTable();
});
</script>
答案 0 :(得分:2)
由于此行,您的订单将被排序为字符串:
data.addColumn('number', 'Order');
这需要更改以使订单排序为数字:
//integer (not really needed unless you need to round numbers, Excel will use default cell properties)
ws.Cells["A1:A25"].Style.Numberformat.Format = "0";
//integer without displaying the number 0 in the cell
ws.Cells["A1:A25"].Style.Numberformat.Format = "#";
//number with 1 decimal place
ws.Cells["A1:A25"].Style.Numberformat.Format = "0.0";
//number with 2 decimal places
ws.Cells["A1:A25"].Style.Numberformat.Format = "0.00";
//number with 2 decimal places and thousand separator
ws.Cells["A1:A25"].Style.Numberformat.Format = "#,##0.00";
//number with 2 decimal places and thousand separator and money symbol
ws.Cells["A1:A25"].Style.Numberformat.Format = "€#,##0.00";
//percentage (1 = 100%, 0.01 = 1%)
ws.Cells["A1:A25"].Style.Numberformat.Format = "0%";
//accounting number format
ws.Cells["A1:A25"].Style.Numberformat.Format = "_-$* #,##0.00_-;-$* #,##0.00_-;_-$* \"-\"??_-;_-@_-";
答案 1 :(得分:1)
除了将列类型更改为'number'
...
data.addColumn('number', 'Order');
在加载行数据时需要从列中删除周围的引号...
from - &gt; '".$item['slide_order']."'
到 - &gt; '.$item['slide_order'].'
以下行...
echo "['".$item['id']."','".$namelink."','".$imagecont."','".$filesizecont."','.$item['slide_order'].','".$statuslink."','".$editlink.$deletelink."' ],\n";
注意:建议使用ajax从php获取数据到javascript,而不是混合在同一个文件中
here is a full example,其中包括以谷歌接受的格式构建json