Got the mulitcolumn search toolbar in place, but it's not working. First I haven't managed to get an autosearch working (searching as you type). Second, and much more critically, I don't have the controller correctly responding to search terms, as it was implemented rather poorly. I'm moving on for now.

git-svn-id: file:///svn-source/pmgr/branches/ledger_transactions_20090605@113 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-06-14 03:22:53 +00:00
parent b4d640f7c2
commit 336ec3b643
2 changed files with 63 additions and 29 deletions

View File

@@ -164,15 +164,25 @@ class AppController extends Controller {
}
function jqGridDataConditions(&$params) {
$searches = array();
if (isset($params['_search']) && $params['_search'] === 'true') {
$op = $params['searchOper'];
$field = $params['searchField'];
$string = $params['searchString'];
if (isset($params['searchOper'])) {
$searches[] = array('op' => $params['searchOper'],
'field' => $params['searchField'],
'value' => $params['searchString']);
}
else {
// DOH! Crappy mechanism puts toolbar search terms
// directly into params as name/value pairs. No
// way to know which elements of params are search
// terms, so skipping this at the moment.
}
}
elseif (isset($params['filt']) && $params['filt']) {
$op = 'bw';
$field = $params['filtField'];
$string = $params['filtString'];
$searches[] = array('op' => 'bw',
'field' => $params['filtField'],
'value' => $params['filtString']);
}
else {
return array();
@@ -189,10 +199,15 @@ class AppController extends Controller {
'cn' => array('op' => 'LIKE', 'pre' => '%', 'post' => '%'),
);
$op = $ops[$op];
$field .= $op['op'] ? ' '.$op['op'] : '';
$string = $op['pre'] . $string . $op['post'];
return array($field => $string);
$conditions = array();
foreach ($searches AS $search) {
$op = $ops[$search['op']];
$field = $search['field'] . ($op['op'] ? ' '.$op['op'] : '');
$value = $op['pre'] . $search['value']. $op['post'];
$conditions[] = array($field => $value);
}
return $conditions;
}
function jqGridDataFields(&$params) {

View File

@@ -35,6 +35,10 @@ $cols['Comment'] = array('index' => 'Customer.comment', 'width' =>
foreach (array_intersect_key($cols, array('Comment'=>1)) AS $k => $v)
$cols[$k]['sortable'] = false;
// Some of the columns should be searchable
foreach (array_intersect_key($cols, array('Last Name'=>1, 'First Name'=>1)) AS $k => $v)
$cols[$k]['search'] = true;
// Create the javascript code for jqGrid to create each table column
$colModels = array();
foreach ($cols AS $col) {
@@ -43,7 +47,7 @@ foreach ($cols AS $col) {
'{ ' . implode(", ",
array_map(create_function
('$k, $v',
'return "$k:".($v===false?"false":"\'$v\'");'),
'return "$k:".($v===false?"false":($v===true?"true":"\'$v\'"));'),
array_keys($col),
array_values($col))) .
'}';
@@ -70,8 +74,8 @@ $url = $html->url(array('controller' => 'customers',
?>
<script type="text/javascript"><!--
jQuery(document).ready(function(){
// return;
jQuery("#customer-list").jqGrid({
url: '<?php echo $url; ?>',
datatype: 'xml',
@@ -89,21 +93,46 @@ jQuery(document).ready(function(){
viewrecords: true,
imgpath: '<?php echo $imgpath; ?>',
caption: <?php echo $caption ? "'$caption'" : "null"; ?>,
toolbar : [true,"bottom"],
});
jQuery("#t_customer-list").height(25).hide()
.filterGrid("#customer-list", {
gridModel:true,
gridToolbar:true,
autosearch:true,
});
jQuery("#customer-list").navGrid('#customer-pager',
{ view:false,
edit:false,
add:false,
del:false,
search:false,
refresh:false})
.navButtonAdd("#customer-pager",{
caption:"Search",
title:"Toggle Search",
buttonimg:'<?php echo $imgpath; ?>' + '/find.gif',
onClickButton:function(){
if(jQuery("#t_customer-list").css("display")=="none") {
jQuery("#t_customer-list").css("display","");
} else {
jQuery("#t_customer-list").css("display","none");
}
}
});
});
--></script>
<div id="everything">
<table id="customer-list" class="scroll"></table>
<div id="customer-pager" class="scroll" style="text-align:center;"></div>
</div>
<div class="h">Search By:</div>
<div>
<input type="checkbox" id="autosearch" onclick="enableAutosubmit(this.checked)">Enable Autosearch
</div>
<div>Last Name<br>
<div>Search By:<BR>
<input type="checkbox" id="autosearch" onclick="enableAutosubmit(this.checked)">Enable Autosearch<BR>
Last Name<BR>
<input type="text" id="filt_last_name" onkeydown="doSearch(arguments[0]||event)" />
<button onclick="gridReload()" id="submitButton" style="margin-left:30px;">Search</button>
</div>
@@ -139,13 +168,3 @@ function gridReload() {
--></script>
<?php
/* <div><a href="#" onClick="$('#debug').html(htmlEncode($('#everything').html())); return false;">Get Table Code</a></div> */
/* <div id="debug"></div> */
/* <P> */
/* <input type="text" id="debval" value="1.0em"><BR> */
/* <a href="#" onClick="$('#load_customer-list').css('display', 'inline'); return false;">Show Loading</a><BR> */
/* <a href="#" onClick="$('#load_customer-list').css('margin-top', $('#debval').val()); return false;">Set Top Margin</a><BR> */
/* <a href="#" onClick="$('#load_customer-list').css('margin-left', $('#debval').val()); return false;">Set Left Margin</a><BR> */
?>