我想添加一个jqgrid到我的laravel刀片;但是,有一个问题“sqlstate[42s22]:column not found:1054‘order子句’中的未知列‘1’(sql:select*from) item
订货人 1
asc限制10偏移量0“)。我不明白为什么。
我的代码如下:
1.5英寸刀片:
$(document).ready(function () {
$("#stock_lost").jqGrid({
url:'{{ URL::route('accountData') }}',
datatype: "json",
colNames:['id','type','model', 'price', 'currency','123'],
colModel:[
{name:'id',index:'id', width:80,key:true,editable:false,hidden:true},
{name:'type',index:'type', width:80,align:'center',editable: true},
{name:'model',index:'model', width:100,align:'center',editable:true},
{name:'price',index:'price', width:80, align:'center',editable:true},
{name:'currency',index:'currency', width:80, align:'center',editable:true},
{name:'storage_location',index:'storage_location', width:80, align:'center',editable:true}
],
//multiselect: true,
//caption: "Manipulating Array Data",
rowNum:10,
rowList:[10,20,30,40,50],
pager:'#lost_pager',
autowidth:true,
height: "auto",
viewrecords:true,
multiselectWidth: 25,
sortable:true,
sortname:'type',
sortorder:'asc',
rownumbers:true,
scrollOffset:0,
cellEdit: false,
});
$('#stock_lost').navGrid("#lost_pager",
// the buttons to appear on the toolbar of the grid
{ edit: true, add: true, del: true, refresh: true, view: false, position: "left", cloneToTop: false },
);
});
</script>
2.5英寸控制器
public function accountData(Request $request){
$page = $request->input('page','1');
$limit = $request->input('limit','10');
$sidx = $request->input('sidx','1');
$sord = $request->input('sord','asc');
$count = item::count();
// calculate the total pages for the query
if( $count > 0 && $limit > 0) {
$total_pages = ceil($count/$limit);
}
else {
$total_pages = 0;
}
if ($page > $total_pages)
$page=$total_pages;
$start = $limit*$page - $limit;
if($start <0)
$start = 0;
$results = DB::table('item')
->orderBy($sidx, $sord)
->skip($start)->take($limit)
->get();
$response= new \ stdClass();
$response->page = $page;
$response->total = $total_pages;
$response->records = $count;
$i=0;
foreach ($results as $result) {
$response->rows[$i]['id']=$i+1;
$response->rows[$i]['cell']=array($result->id, $result->type,$result->model, $result->price, $result->currency, $result->storage_location);
$i++;
}
return json_encode($response);
}
3.1网络
Route::get('/lost','StockController@accountData')->name('accountData');
4.表格“item”的模型
namespace App;
use Illuminate\Database\Eloquent\Model;
class item extends Model
{
protected $table='item';
protected $primaryKey='id';
protected $fillable=[
"type",
"model",
"price",
"currency",
"storage_location",
];
}
暂无答案!
目前还没有任何答案,快来回答吧!