That worked thanks, code for other users is:
|
1 2 3 4 5 6 7 8 9 10 11 |
$scrollbar = <<<EOT function(xhr){ if (jQuery('#grid').jqGrid('getGridParam', 'reccount') == 0) jQuery(".ui-jqgrid-hdiv").css("overflow-x", "scroll") else jQuery(".ui-jqgrid-hdiv").css("overflow-x", "hidden") } EOT; $grid->setGridEvent('loadComplete', $scrollbar); |
In jqGrid PHP you can do:
require_onceĀ ABSPATH.”php/PHPSuito/DBdrivers/jqGridArray.php”;
Then rather than reading data from a database you can read it from an array, I wondered if TreeGrid also supported this and if it could build the tree based on a multidimensional array as in the example?
This is fantasic and works a treat, many thanks.
Many thanks, I will look forward to the next release.
Thanks for the reply but I’m struggling to get that to work, I will give you the actual example for priority.
The data contains values 1,2,3,4 or 5 which then displays as text to the user
I’ve only given part of the code, but it’s the most relevant parts (rather than a 400 odd line file) š
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
$dataInit = <<< DATAINIT function(elem) { var options = { height: "150", minWidth : 'auto', noneSelectedText: 'Select', open: function () { var mmenu = $(".ui-multiselect-menu:visible"); mmenu.css("font-size","11px").width("auto"); return; } }, melem = $(elem); melem.multiselect(options); melem.siblings('button.ui-multiselect').css({ width: "100%", marginTop: "1px", marginBottom: "1px", paddingTop: "3px" }); } DATAINIT; $grid->setSelect("priority", array("5" => "Emergency", "4" => "High", "3" => "Medium", "2" => "Low", "1" => "Info"), true, true, false); $grid->setColProperty('priority', array( "searchoptions"=>array( "multiple"=>true, "dataInit"=>"js:".$dataInit, "defaultValue"=> "1,2", // Also tried Info,Low here "sopt" => "eq" )) ); $searcharr["groupOp"] = "AND"; $searcharr["rules"][] = [ "field" => "priority", "op" => "eq", "data" => "1,2" ]; $grid->setGridOptions(array( "scroll" => false, "rowNum" => 20, "sortname" => "alert_time", "sortorder" => "desc", "sortable" => "true", "height"=>600, "multiSort" => true, "loadonce" => true, "autowidth" => true, "shrinkToFit" => false, "search" => true, "postData" => array("filters" => json_encode($searcharr)), //"colMenu" => true, // Can't get colMenu working with multiple )); $grid->setNavOptions('navigator', ["refresh" => false, "reload" => false, "excel" => false, "add" => false, "edit" => false, "del" => false, "view" => true, "search" => true, "columns" => true,]); $grid->setNavOptions('search', array("multipleSearch" => true, "uniqueSearchFields" => true, "multipleGroup" => true, "showQuery" => true)); $grid->renderGrid('#grid', '#pager', true, null, null, true, true); |
Many thanks, I’ve downloaded the latest theme CSS and added this to the end which has appeared to have cleaned things up.
I know this is a really old thread, but does anyone know if this tutorial is still available?
I’m just moving over to CakePHP and are running into a bit of trouble where to place the files, paths, should the main content be in the controller or view etc.
Thanks.
Many thanks, great support, I will check it out.
Hi Support,
Many thanks for the reply, I understand SetSelect will set the data for the drop-down/searching, will it also set the data in the action grid itself?
Also can SetSelect be an SQL query rather than an array (else it will be a massive array)
Source Data:
[TABLE]
[TR][TD]host[/TD][TD]Service[/TD][TD]Other Data[/TD][/TR]
[TR][TD]1[/TD][TD]1[/TD][TD]Hello 1234[/TD][/TR]
[TR][TD]2[/TD][TD]1[/TD][TD]Hello 1234[/TD][/TR]
[TR][TD]2[/TD][TD]2[/TD][TD]Hello 1234[/TD][/TR]
[/TABLE]
Data in UI:
[TABLE]
[TR][TD]host[/TD][TD]Service[/TD][TD]Other Data[/TD][/TR]
[TR][TD]Host A[/TD][TD]Service A[/TD][TD]Hello 1234[/TD][/TR]
[TR][TD]Host B[/TD][TD]Service A[/TD][TD]Hello 1234[/TD][/TR]
[TR][TD]Host B[/TD][TD]Service B[/TD][TD]Hello 1234[/TD][/TR]
[/TABLE]
Many thanks.
Hi Will,
Many thanks for the reply, I’ve taken a look at the site you selected and downloaded the code, but I’m having issues targeting it into Guriddo, I’ve tried the following:
Any ideas? Ā It would be good to have this natively in the solution at some point as a feature request.
<script>
$.datepicker._defaults.onAfterUpdate = null;
var datepicker__updateDatepicker = $.datepicker._updateDatepicker;
$.datepicker._updateDatepicker = function( inst ) {
datepicker__updateDatepicker.call( this, inst );
var onAfterUpdate = this._get(inst, ‘onAfterUpdate’);
if (onAfterUpdate)
onAfterUpdate.apply((inst.input ? inst.input[0] : null),
[(inst.input ? inst.input.val() : ”), inst]);
}
$(document).ready(function() {
var cur = -1, prv = -1;
$(‘<input id=”jrangeinput”>‘).appendTo(‘#gs_alert_time’);
$(‘#jrange div’)
.datepicker({
//numberOfMonths: 3,
changeMonth: true,
changeYear: true,
showButtonPanel: true,
defaultDate: -10,
setDate: ’10-Jul-2016′,
maxDate: 0,
beforeShowDay: function ( date ) {
return [true, ( (date.getTime() >= Math.min(prv, cur) && date.getTime() <= Math.max(prv, cur)) ? ‘date-range-selected’ : ”)];
},
onSelect: function ( dateText, inst ) {
var d1, d2;
prv = cur;
cur = (new Date(inst.selectedYear, inst.selectedMonth, inst.selectedDay)).getTime();
if ( prv == -1 || prv == cur ) {
prv = cur;
//$(‘#jrange input’).val( dateText );
$(‘#jrange input’).val( $.datepicker.formatDate( ‘dd-M-y’, new Date(Math.min(prv,cur)), {} ));
} else {
d1 = $.datepicker.formatDate( ‘dd-M-y’, new Date(Math.min(prv,cur)), {} );
d2 = $.datepicker.formatDate( ‘dd-M-y’, new Date(Math.max(prv,cur)), {} );
$(‘#jrange input’).val( d1+’ to ‘+d2 );
}
},
onChangeMonthYear: function ( year, month, inst ) {
//prv = cur = -1;
},
onAfterUpdate: function ( inst ) {
$(‘<button type=”button” class=”ui-datepicker-close ui-state-default ui-priority-primary ui-corner-all” data-handler=”hide” data-event=”click”>Done</button>’)
.appendTo($(‘#jrange div .ui-datepicker-buttonpane’))
.on(‘click’, function () { $(‘#jrange div’).hide(); });
}
})
.position({
my: ‘left top’,
at: ‘left bottom’,
of: $(‘#jrange input’)
})
.hide();$(document).ready(function(){
// Populate the inputbox by default
var dateload = $(‘#jrange div’).datepicker(‘getDate’);
var dateload2 = $.datepicker.formatDate( ‘dd-M-y’, dateload);$(‘#jrange input’).val(dateload2);
});$(‘#jrange input’).on(‘focus’, function (e) {
var v = this.value,
d;
try {
if ( v.indexOf(‘ to ‘) > -1 ) {
d = v.split(‘ to ‘);
prv = $.datepicker.parseDate( ‘dd-M-y’, d[0] ).getTime();
cur = $.datepicker.parseDate( ‘dd-M-y’, d[1] ).getTime();
} else if ( v.length > 0 ) {
prv = cur = $.datepicker.parseDate( ‘dd-M-y’, v ).getTime();
}
} catch ( e ) {
cur = prv = -1;
}
if ( cur > -1 )
$(‘#jrange div’).datepicker(‘setDate’, new Date(cur));
$(‘#jrange div’).datepicker(‘refresh’).show();
});
});
</script>
Many thanks for your reply, that fixed the problem.
Just one quick additional problem is it possible to default my date-picker to -10 days by default and allow the user to specify a date range?
I can’t see a way to do this in the jQuery UI without to fields
Many thanks and assure you I won’t bother you any more after that.
Thanks.
E-mailed you with a dropbox link to the code, many thanks for your help.
Works a dream thanks, I don’t know why the built in refresh has issues but this works for me.
That works a lot better thanks, just a final piece of the puzzle to solve.
When loading this way the sorting and column widths don’t reload. I’d rather have all the information stored in the database, but tried using:
schema['colmodel'] = jQuery('#grid').jqGrid('getGridParam','colModel');
then
jQuery('#grid').jqGrid('setGridParam',{colModel:obj['colmodel']}).trigger("reloadGrid");
But it doesn’t seem to work, so plan B, use load storage:
$.jgrid.saveState("grid");
then
$.jgrid.loadState("grid");
I have a lot more success with this, as the grid loads all the preferences, but all the icons in the “pager” toolbar disappear, looking in the console there is a JavaScript error:
Uncaught TypeError: Cannot read property 'beforeProcessing' of undefined$.ajax.$.extend.success @ jquery.jqGrid.min.js:10j @ jquery.min.js:2k.fireWith @ jquery.min.js:2x @ jquery.min.js:4(anonymous function) @ jquery.min.js:4
Get this working then everything is good, thanks again for the extended support.
There are two ways to activate this issue either:
1. Save the Layout and Reload it
2. Refresh the grid and new records get inserted
Here is what I did, load the Grid inside a new browser window (sorry I have to blank some data)

Now I tick High the system correctly filters the grid. When I press this High checkbox an event it fired that refreshes the grid in a different way to jQuery(‘#grid’).trigger(“reloadGrid”); that I want to mimic.
I save the layout and press F5 to reload the entire browser window, then press load, my filters are correctly applied however the data in the grid doesn’t reload correctly.
However if I uncheck High from the priority dropdown and choose it again the data displays correctly.
I get the same issue if I press the refresh button on the lower toolbar and new records have been added to the database outside the filter.
So what I want to do is manually trigger the refresh in the same way the multipick does it, then attach this to my load function and the refresh function of the grid.
Here is the code from my load/save functions, you will notice I also tried to Save the layout (not the data) of the grid, I wanted to save the width and order of the columns, the sorting order, I’ve commented this out because I couldn’t get it to work, but I’ve left it in below, in case you notice some easy fixes in that code as well.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
function savelayout() { var schema = {}; schema['postdata'] = jQuery('#grid').jqGrid('getGridParam','postData'); //schema['colmodel'] = jQuery('#grid').jqGrid('getGridParam','colModel'); //$.jgrid.saveState("grid"); schema['sortname'] = jQuery('#grid').jqGrid('getGridParam','sortname'); schema['sortorder'] = jQuery('#grid').jqGrid('getGridParam','sortorder'); console.log (schema); jQuery.post("alertprocessor_ajax.php?mode=savelayout", { data: JSON.stringify(schema) }) .done(function() { alert("Layout Saved Successfully."); }) .fail(function (){ alert("Layout Save Failure"); }); }; function loadlayout() { jQuery.get("alertprocessor_ajax.php?mode=loadlayout", function (data) { console.log ("Data is - " + data + "That is it"); var obj = JSON.parse(data); console.log (obj); jQuery('#grid').jqGrid('setGridParam',{ postData: obj['postdata'], //sortname: obj['sortname'], //sortorder: obj['sortorder'] }).trigger("reloadGrid"); // TODO: Need to debug the column widths, why the don't save and reload //jQuery('#grid').jqGrid('setGridParam',{colModel: obj['colmodel']}).trigger("reloadGrid"); jQuery('#grid').jqGrid('refreshFilterToolbar', {filters: obj['postdata'].filters}); // finally refresh the multiselect plugin var items = jQuery("[aria-multiselectable=true]"); jQuery.each(items,function () { var obj = jQuery('#' + this.id); obj.multiselect('refresh'); obj.siblings('button.ui-multiselect').css({ width: "100%", marginTop: "1px", marginBottom: "1px", paddingTop: "3px" }); }); // Disabled as it hides the toolbar due to an error //$.jgrid.loadState("grid"); alert("Layout Loaded Successfully."); }); }; |
Many thanks
Copyright 2014 TriRand LtdAll Rights ReservedRSS
Back to Top