Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [Cake]Wyszukiwanie danych z zakresu dat, jQuery Datepicker - date range
QeX
post
Post #1





Grupa: Zarejestrowani
Postów: 11
Pomógł: 0
Dołączył: 13.04.2012

Ostrzeżenie: (0%)
-----


Witam,

Jest w tabeli pewna liczba dokumentów zawierających w treści daty. Aktualnie realizowane jest wyszukiwanie po konkretnej dacie (pole contdate).

Kod kontrolera:

  1. if(isset($this->request->data['Doc']['contdate']) && trim($this->request->data['Doc']['contdate']) != ''){
  2. $conditions[] = array('DATE(Doc.contdate) ' => $this->request->data['Doc']['contdate']);
  3. $this->set('docs', $this->Doc->find('all', array('conditions' => $conditions)));
  4. }


Kod widoku:

  1. echo $this->Form->create('Doc', array('inputDefaults' => array('label' => false,'div' => false)));
  2. echo $this->Form->input('contdate', array('type' => 'text', 'label' => 'Wpisz datę:<br>'));



Chciałbym zrealizować wyszukiwanie dokumentów z określonego zakresu dat, przy pomocy jQuery Datepicker. Jak "spiąć" Datepickera z zawartością tabeli docs?

Kod Datepickera z formularzem:

CODE
$("#from").datepicker({
maxDate: 0,
onSelect: function( selectedDate ) {
$("#to").datepicker( "option", "minDate", selectedDate );
}
});
$("#to").datepicker({
maxDate: 0,
onSelect: function( selectedDate ) {
$("#from").datepicker( "option", "maxDate", selectedDate );
}
});

<label for="from">From</label>
<input type="text" id="from" name="from"/>
<label for="to">to</label>
<input type="text" id="to" name="to"/>

Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
kleus
post
Post #2





Grupa: Zarejestrowani
Postów: 93
Pomógł: 7
Dołączył: 22.10.2009
Skąd: Siędzę

Ostrzeżenie: (0%)
-----


ja mam tak u siebie zrobione
PostsController
  1. public function admin_index(){
  2. $this->paginate = array(
  3. 'order' => 'Post.published DESC',
  4. 'limit' => '10',
  5. 'conditions' => array(
  6.  
  7. )
  8. );
  9. if($this->RequestHandler->isAjax()){
  10. $this->paginate['conditions'] = Set::merge(
  11. $this->paginate['conditions'],
  12. 'Post.modified BETWEEN ? AND ?' => array($this->request->data['Post']['from'], $this->request->data['Post']['to'])
  13. )
  14. );
  15. }
  16. $Posts = $this->paginate('Post');
  17. $this->set(compact('Posts'));
  18. if($this->RequestHandler->isAjax()){
  19. $this->render('ajax/admin_indexUpdate');
  20. }
  21. }

admin_index.ctp
  1. <?php
  2. $url = array(
  3. 'plugin' => false,
  4. 'controller' => 'posts',
  5. 'admin' => true,
  6. 'prefix' => 'admin'
  7. );
  8.  
  9. $this->Html->addCrumb('Blog', array(
  10. 'plugin' => false,
  11. 'controller' => 'posts',
  12. 'action' => 'index',
  13. 'admin' => true,
  14. 'prefix' => 'admin'
  15. ));
  16. ?>
  17. <section class="row">
  18. <?php
  19. echo $this->Form->create(null, array('id' => 'dateUpdate'));
  20. echo $this->Form->input('from', array(
  21. 'class' => 'input-append date',
  22. 'id' => 'dp',
  23. 'value' => date('Y-m-d')
  24. ));
  25. echo $this->Form->input('to', array(
  26. 'class' => 'input-append date',
  27. 'id' => 'dp2',
  28. 'value' => date('Y-m-d')
  29. ));
  30. echo $this->Form->end();
  31. $data = $this->Js->get('#dateUpdate')->serializeForm(array(
  32. 'isForm' => true,
  33. 'inline' => true
  34. ));
  35. $this->Js->get('#dateUpdate')->event('change',
  36. $this->Js->request(
  37. Router::url(array(
  38. 'controller' => 'posts',
  39. 'action' => 'index',
  40. 'admin' => true // or false //
  41. )),
  42. 'update' => '#update',
  43. 'async' => true,
  44. 'dataExpression'=>true,
  45. 'method' => 'POST',
  46. 'data' => $data
  47. )
  48. ));
  49. echo $this->Html->scriptBlock("
  50. $('#dp').datepicker({dateFormat: 'yy-mm-dd'});
  51. $('#dp2').datepicker({dateFormat: 'yy-mm-dd'});
  52. ");
  53. ?>
  54. <section class="span8" id="update">
  55. <?php echo $this->element('BootstrapPagination', array('update' => 'update')); ?>
  56. <table class="table table-bordered">
  57. <?php echo $this->Html->tableHeaders(array(
  58. $this->Paginator->sort('id'),
  59. $this->Paginator->sort('status'),
  60. $this->Paginator->sort('modified'),
  61. $this->Paginator->sort('title'),
  62. $this->Paginator->sort('author'),
  63. 'Actions'
  64. )); ?>
  65. <?php foreach($Posts as $k => $Post): ?>
  66. <?php
  67. switch($Post['Post']['status']){
  68. case '0':
  69. $Post = array_merge($Post, array('status' => 'Unpublished'));
  70. break;
  71. case '1':
  72. $Post = array_merge($Post, array('status' => 'Published'));
  73. }
  74. ?>
  75. <?php echo $this->Html->tableCells(array(
  76. h($Post['Post']['id']),
  77. h($Post['status']),
  78. h(
  79. $this->Time->format('Y-m-d H:i:s', $Post['Post']['modified'], false, $_SESSION['timezone'])
  80. ),
  81. h($Post['Post']['title']),
  82. h($Post['User']['name']),
  83. $this->Html->Link('',
  84. array_merge($url, array('action' => 'delete', $Post['Post']['id'])),
  85. array('class' => 'icon-trash'),
  86. __('Are you sure?'), false
  87. ),
  88. $this->Html->Link('',
  89. array_merge($url, array('action' => 'view', $Post['Post']['id'])),
  90. array('class' => 'icon-eye-open')
  91. ),
  92. $this->Html->Link('',
  93. array_merge($url, array('action' => 'edit', $Post['Post']['id'])),
  94. array('class' => 'icon-edit')
  95. )
  96. )); ?>
  97. <?php endforeach; ?>
  98. </table>
  99. <?php echo $this->element('BootstrapPagination'); ?>
  100. </section>
  101. <aisde class="span3 offset1">
  102. <ul class="nav nav-list">
  103. <li class="nav-header actions">
  104. Blog Actions
  105. </li>
  106. <li class="divider"></li>
  107. <li><?php echo $this->Html->link(__('List Posts'), array_merge(
  108. $url, array('action' => 'index')
  109. )); ?></li>
  110. <li><?php echo $this->Html->link(__('New Post'), array_merge(
  111. $url, array('action' => 'add')
  112. )); ?></li>
  113. </ul>
  114. </aside>
  115. </section>


i śmiga
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 14.10.2025 - 21:52