0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【Rails】 DataTables 検索結果の保持方法

Posted at

はじめに

これまでに Rails + DataTable 関連の記事を書いてきましたが、別のページから戻ってきた時に検索結果を保持していて欲しいなどのユーザーの要望があるかと思いますので、そのような細かい設定の変更方法について今回はまとめさせていただきます。

関連リンク

関連リンクを下記に載せておくので、必要であれば参考にしてください。。

検索結果の保持方法

次の2つを設定するだけで、検索結果を保持してくれるようになります。

  • stateSave
  • stateDuration
app/assets/javascripts/concern/datatables.coffee
class @DataTables
  # *** 省略 ***
  drawTable: ->
    # *** 省略 ***

    # stateSave : 別のページから戻ってきた時に検索結果を保持するかどうかを設定可能(trueが保持)
    stateSave: true,

    # stateDuration : stateSave の検索結果の保持する時間を設定可能(1秒単位で設定可能)
    stateDuration: 60 * 15,   # sec * min

  # *** 省略 ***

まとめ

英語のドキュメントさえ読んで使いこなすことができれば、DataTablesはユーザーのニーズを柔軟に反映した高機能なテーブルを短時間で実装することができます。
Rails と組み合わせると爆速で開発が捗ると思っているので、ぜひ活用してみてください。

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?