0

JSONタイプのデータストアを持つ道場データグリッドがあります。mysql データベースから取得したデータを表示することは既に完了しています。私がやりたいことは、ページネーションを許可し、行データを編集可能にして、編集したデータをデータベースに更新することです。これが私がこれまでに得たものです:

<style type="text/css">
    @import "dojoroot/dijit/themes/claro/claro.css";
    @import "dojoroot/dojo/resources/dojo.css";
    @import "dojoroot/dojox/grid/enhanced/resources/claro/EnhancedGrid.css";
    @import "dojoroot/dojox/grid/enhanced/resources/EnhancedGrid_rtl.css";

</style>
<script type="text/javascript" src="dojoroot/dojo/dojo.js" data-dojo-config="async: true, isDebug: true, parseOnLoad: true"></script>
<script type="text/javascript">

require(["dojo/store/JsonRest"], function(JsonRest){
    myStore = new JsonRest({target:"jsonExample.php"});
});
require([
"dojox/grid/EnhancedGrid",
"dojox/grid/enhanced/plugins/Pagination",
"dojo/data/ObjectStore",
"dojo/domReady!",
"dijit/form/Form"
], function(DataGrid, ObjectStore){
grid = new DataGrid({
store: dataStore = ObjectStore({objectStore: myStore}),
editable:true,
structure: [
    {name:"ID", field:"writer_id", width: "50px"},
    {name:"Writer's Name", field:"writer_name", width: "200px", editable: true},
    {name:"Writer's Email", field:"writer_email", width: "200px", editable: true}
],
//declare usage of plugins
plugins: {
    pagination: {
        sizeSwitch: false,
        defaultPageSize: 10
    }
},
}, "target-node-id"); // make sure you have a target HTML element with this id
grid.startup();
});
</script>

jsonExample.php は mysql からデータを取得し、データを json 形式に変換します

<?php
$db=mysql_connect("localhost","root","") or die("could not connect to mysql server");
mysql_select_db("demo",$db) or die("could not connect to database");
$query="SELECT * FROM writers";
$resultSet=mysql_query($query,$db);
$arr = array();
while($row = mysql_fetch_object($resultSet)){               
    $arr[] = $row;
}
$jsonStr = json_encode($arr);
mysql_close($db);
echo "{$jsonStr}";
?>

javascript コンソールに次のエラーが表示されます this.option is undefined this.defaultPage=this.option.defaultPage>=1?parseInt(this.option.defaultPage,10):1;

4

2 に答える 2

1

グリッドを編集可能にするには、次のように、グリッド レイアウト (構造) 列を編集可能に設定する必要があります。

structure: [
    {name:"ID", field:"writer_id", width: "50px"},
    {name:"Writer's Name", field:"writer_name", width: "200px", editable: true, type: dijit.form.TextBox}, //make editable and use input
    {name:"Writer's Email", field:"writer_email", width: "200px", editable: true, type: dijit.form.Textarea} //make editable and use textarea
]

ページネーションを有効にするには、DataGrid の代わりにdojox/grid/EnhancedGridを使用し、 dojox/grid/enhanced/plugins/Paginationという名前のプラグインをロードする必要があります。

次に、ページネーション プラグインの使用法を次のように宣言します。

grid = new dojox.grid.EnhancedGrid({
    store: dataStore = ObjectStore({objectStore: myStore}),
    editable:true,
    structure: [
        {name:"ID", field:"writer_id", width: "50px"},
        {name:"Writer's Name", field:"writer_name", width: "200px", editable: true},
        {name:"Writer's Email", field:"writer_email", width: "200px", editable: true}
    ],
    //declare usage of plugins
    plugins: {
        pagination: {
            sizeSwitch: false,
            defaultPageSize: 10
        }
    }
}, "target-node-id")

その後、JsonRestStore を使用しているため、php コードを使用してバックエンドでソートとページネーションのロジックを実装する必要があります。

並べ替えとページ情報は、グリッドの ajax リクエストのリクエスト ヘッダーを介してバックエンドに渡されます。したがって、必要なのは、ソートとページ ヘッダーを解析し、モデルの正しい json データを返すことだけです。その他の例と詳細については、このチュートリアルを参照してください。

于 2012-06-18T07:49:15.197 に答える
0

http://pradipchitrakar.com.np/programming/dojo-grid-php-mysql-with-pagination/にソリューションを投稿し、 http://pradipchitrakar.com.np/demos/dojogrid/にデモを掲載しました

于 2012-06-20T18:58:57.667 に答える