0

I have a grid that I created using the jqGrid PHP API and the Choose Columns add-on (to show/hide columns). I need to add the ability to save the grid state (after doing any filtering, altering the column order or hiding any columns).

I've seen several posts that use either cookies or a localStore to save the state of the grid. However, I want to be able to save it in a database so that I can restore it later, the next time the user logs into the system.

Here's the PHP code I have for the grid:

    require_once JQGRID_PATH."php/jqGrid.php";
    require_once JQGRID_PATH."php/jqGridPdo.php";

    // Connection to the server
    $conn = new PDO(DB_DSN,DB_USER,DB_PASS);

    // Create the jqGrid instance
    $grid = new jqGridRender($conn);

    // Write the SQL Query
    $grid->SelectCommand = 'SELECT timestamp, user_name, action_type FROM audit_log';

    // set the ouput format to json
    $grid->dataType = 'json';

    // Let the grid create the model
    $grid->setColModel();

    // Set the url from where we obtain the data
    $grid->setUrl('audit_log');

    // Set grid caption using the option caption
    $grid->setGridOptions(array(
        "caption"=>"Audit Log Report",
        "height"=>470,
        "width" => 1100,
        "rowNum"=>25,
        "shrinkToFit"=>false,
        "sortname"=>"timestamp",
        "sortorder"=>"desc",
        "rowList"=>array(25,50,100)
    )); 

    $grid->navigator = true;
    $grid->setNavOptions(
        'navigator', array(
            "excel"=>true,
            "add"=>false,
            "edit"=>false,
            "view"=>false,
            "del"=>false,
            "pdf"=>true
        )
    );

    $grid->renderGrid('#grid','#pager', true, null, null, true, true, true);

Also, the posts that I've seen that use localStore to save the grid state are all built using jQuery and not the jqGrid PHP Suite. Any ideas on how I can accomplish this with the jqGrid PHP API?

Any help would be greatly appreciated.

Thanks!

4

2 に答える 2

0

グリッド オプションが配列である場合、その配列をシリアル化し、そのユーザーに関連付けられたレコードでデータベースに保存してみませんか?

本当に凝ったものにしたい場合は、jqGridRender クラスをpersist()やなどのメソッドで拡張しload()て、オプションを DB に保持し、それらを再度ロードすることができます。

したがって、何らかのユーザー オブジェクトがあると仮定すると、おそらく次のようにします。

$grid = new persistingJQGrid($conn); // instantiate your special extended class
$grid->setUser($user);
$grid->load();
...

または持続する場合:

$grid->persist()
于 2013-01-11T00:07:12.540 に答える
0

回答では、グリッドの状態を表す情報を保存する方法と、localStorageその情報を使用してグリッドを作成する方法を示しました。回答では、状態を表すオブジェクトをローカル ストレージに保存するためsaveObjectInLocalStorageに使用するメソッドを見つけることができます。window.localStorage.setItem情報をデータベースに保存する必要がある場合は、情報をサーバーに送信するものをwindow.localStorage.setItem置き換えるだけです。同様に、グリッドの初期化中に使用済みを一度$.ajax置き換えて、データの初期化を、以前に保存された、データベースから読み取られた状態で直接行うことができます。したがって、アプローチは、グリッドの状態を保持する任意の場所に簡単に変更できます。getObjectFromLocalStorage

于 2013-01-11T09:04:46.393 に答える