我试图将jqgrid集成到Laravel一周,我发现的唯一软件包是Mgallegos的软件包,不幸的是,对于像我这样的新手来说太复杂了。这里是我的代码,任何帮助将不胜感激路线
Route::post('/test',array('as'=>'ajax.test','uses'=>'TestController@getTestData'));
模型
class People extends Eloquent
{
public $timestamps = false;
protected $table = "people";
protected $guarded = array("*");
protected $fillable = array("Name", "Age", "RecordDate");
}
TestController
Class TestController extends BaseController {
public function getTestData()
{
$companies = People::all();
return Response::json($companies);
}
}
查看Test.php
<!DOCTYPE html>
<html lang="en">
<head>
<title>jQGrid example</title>
<link rel='stylesheet' type='text/css' href='http://code.jquery.com/ui/1.10.3/themes/redmond/jquery-ui.css' />
<link rel='stylesheet' type='text/css' href='http://www.trirand.com/blog/jqgrid/themes/ui.jqgrid.css' />
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script type='text/javascript' src='http://www.trirand.com/blog/jqgrid/js/jquery-ui-custom.min.js'></script>
<script type='text/javascript' src='http://www.trirand.com/blog/jqgrid/js/i18n/grid.locale-en.js'></script>
<script type='text/javascript' src='http://www.trirand.com/blog/jqgrid/js/jquery.jqGrid.js'></script>
</head>
<body>
<script>
$(document).ready(function () {
// prepare the data
var source ={
datatype: "json",
datafields: [{ name: 'id' },{ name: 'Name' },{ name: 'Age' },,],
url: '{{ URL::route("ajax.test") }}'
};
$("#jqgrid").jqGrid({
source: source,
theme: 'classic',
columns: [
{ text: 'id', datafield: 'id', width: 250 },
{ text: 'Name', datafield: 'Name', width: 150 },
{ text: 'Age', datafield: 'Age', width: 180 }
]
});
});
<div id="jqgrid"></div>
</script>
</body>
</html>
这些代码给我错误:MethodNotAllowedHttpException我真正需要的是涵盖后续路线/控制器/模型/视图的教程或工作代码。我正在使用Laravel 4.1.30。感谢进阶与路线
Route::get('/test',array('as'=>'ajax.test','uses'=>'TestController@getTestData'));
+--------+---------------+-----------+----------------------------+----------------+---------------+
| Domain | URI | Name | Action | Before Filters | After Filters |
+--------+---------------+-----------+----------------------------+----------------+---------------+
| | GET|HEAD test | ajax.test | TestController@getTestData | | |
+--------+---------------+-----------+----------------------------+----------------+---------------+
以下两条建议可能会有所帮助:
.jqgrid
,使用方法.jqxGrid
,这是一个完全不同的插件。