Below is my grid ..
the Column TestType has a list of values (say test1, test2..test10 ) .
how can i generate Add form like this.
Can any one throw some light on this?
many thanks..
UPDATED:
========
this is how my add form should look like
As I Understand from your above comments, Your add form need to be in Tabular format.
A. Easy way is Grid inline edit. But I think it is not suitable for you. If so,
B. Do the following:
Instead of grid's default add button use external add button. On clicking that button open a custom form in tabular form with Save option.
Onclick of save button just read all fields data from the tabular form. Here you have some small problem.
You may have to iterate the rows in the table to insert into the Database (This is Based on your database design).
On success of AJAX you just reload the Grid by using $('#yourGrid').trigger("reloadGrid");
This is a design idea only. Unfortunately I do not have any example for you :(
Let me know if you need more details.
Edit:
External add button:
Resulted add form:
Do you create a jqgrid in your form?
You are have create a jqgrid like this:
jQuery("#list2").jqGrid({
url:'server.php?q=2',
datatype: "json",
colNames:['Inv No','Date', 'Client', 'Amount','Tax','Total','Notes'],
colModel:[
{name:'id',index:'id', width:55},
{name:'invdate',index:'invdate', width:90},
{name:'name',index:'name asc, invdate', width:100},
{name:'amount',index:'amount', width:80, align:"right"},
{name:'tax',index:'tax', width:80, align:"right"},
{name:'total',index:'total', width:80,align:"right"},
{name:'note',index:'note', width:150, sortable:false}
],
rowNum:10,
rowList:[10,20,30],
pager: '#pager2',
sortname: 'id',
viewrecords: true,
sortorder: "desc",
caption:"JSON Example"
});
jQuery("#list2").jqGrid('navGrid','#pager2',{edit:false,add:false,del:false});
Where colNames its a caption, colModel contain a name and format you grid, and exists a tag PostData contain a arguments for populate your grid, its return a format JSON or Xml.
Do you see more in a Wiki and Demos.
You're Welcome.
One solution could be to go 'out of band' with jqgrid. you could add an 'onSelectRow' attribute to your jqGrid javascript-object. Allowing it to load up some other content, say for instance in a dialog. this would look like this.
$("#list").jqGrid({
url:'/path/to/jqgrid/data/',
datatype: 'json',
mtype: 'GET',
colNames:['TestID','ArticleID', 'Color', 'TestType', 'Places Tested', 'Results', 'comments'],
colModel :[
{name:'testid', index:'testid', width:35, align:'center', sortable:true},
{name:'artileid', index:'articleid', width:50, align:'left', sortable:false},
{name:'color', index:'color', width:80, align:'left', sortable:true},
{name:'testtype', index:'testtype', width:40, align:'right', sortable:true},
{name:'placestested', index:'placestested', width:50, align:'center', sortable:false},
{name:'results', index:'results', width:50, align:'center', sortable:false},
{name:'comments', index:'commente', width:35, align:'center', sortable:false}
],
pager: '#pager',
rowNum:15,
rowList:[15,30,60,120],
sortname: 'testid',
sortorder: 'desc',
viewrecords: true,
gridview: true,
emptyrecords: "No Tests in system",
height: "100%",
autowidth: true,
caption: 'Test Details',
onSelectRow: function(id, status, event){
console.log("jqGrid.onSelectRow called");
alert('TODO: add dialog');
var url = "/new/dialog/server/data/' + id + "/"
console.log(url);
window.openDialog( url, id );
$('tr[id=' + id + ']').removeClass('ui-state-highlight'); // no annoying white row.
},
loadComplete: function() {
console.log('jqGrid.loadcomplete');
}
}); // end jqGrid stanza
Not Quite Finished:
Now you need to do 3 things
Build the server response: that will respond to the jqgrid url request. '/path/to/jqgrid/data/'
you will need to write your javascript 'openDialog(url, id)' function. This should be a wrapper function to a jquery-ui dialog.
you will need to build another server response: that will respond to the openDialog url request.
Note: I recommend since you are using jqGrid, you would be using a jquery-ui dialog.
Finally: 'just to be sure' the response that you are going to need from # 1 will look something like this.
{
"total": 1,
"records": 2,
"rows": [
{
"cell": [ 1, 398, "red", "unit", "lab", "failed", "failed post progression bla" ],
"id": 2
},
{
"cell": [ 2,399, "green", "unit", "lab", "passed", "past post progression bla" ],
"id": 1
}
],
"page": 1
}
Related
The jqgrid rowlist dropdown is missing.
Missing jqgrid rolwist dropdown http://www.managementlevelreview.com/images/MissingRowlist.jpg
My code:
jQuery("#gridsavedAfterHours").jqGrid({
url:'/AfterHours/GetsavedAfterHours?userid=${thisuserid}&&orgcode=${thisorgcode}',
datatype: 'json',
colNames:['ID','Name','Branch','Start','End'],
colModel:[
{name:'AfterHoursId', index:'AfterHoursId', width:25, sortable:true, search:false, key: true},
{name:'UserFullName', index:'UserFullName', width:150, sortable:true, search:false},
{name:'UserOrgLongName', index:'UserOrgLongName', width:150, sortable:true, search:false},
{name:'enteredStartDate', index:'enteredStartDate', width:100, sortable:true, search:false},
{name:'enteredEndDate', index:'enteredEndDate', width:100, sortable:true, search:false}
],
rowNum:${DefaultRowNumber ?? 10},
rowList:[10,25,50,100],
pager: jQuery('#savedAfterHoursPager'),
onSelectRow: function(id){},
sortname: 'Start',
viewrecords: true,
sortorder: 'desc',
multiselect: false,
imgpath: '/Content/images',
caption: 'After Hours',
height: 'auto',
width: '800px',
emptyrecords: 'No After Hours data found.'
}).navGrid('#savedAfterHoursPager',
{edit:false,add:false,del:false},
{}, // use default settings for edit
{}, // use default settings for add
{}, // delete instead that del:false we need this
{ //search options
closeOnEscape:true /* allow the view dialog to be closed when user press ESC key*/
}
);
I suppose that you defined some CSS style for input field which has large width attribute and probably some other attributes. I recommend you to include the following additional CSS on your page
input.ui-pg-input { width: auto; }
See additionally another answer on the close subject.
I am using a jqgrid but am having trouble positioning to a specific page. I have seen a couple of examples using reloadGrid which I have tried but it doesn't work. I have a large data set that is paged. If I try to go to page 76 of my data set it acts like it is trying to do it as the "View" count at the bottom is correct however the grid is displayed empty (even though my JSON data looks correct). I notice the scroll bar is still positioned to the top and if I touch it it automatically reloads back to page 1. Am I missing something?
Here is my grid definition:
$("#list1").jqGrid({
url: 'jqgrid.php?cmd=getrecs',
editurl: 'jqgrid.php?cmd=editrec',
datatype: 'json',
colNames:['Branch', 'Description', 'Type', 'Active' ],
colModel :[
{name:'rbranch',
index:'rbranch',
sortable:true,
editable:true
},
{name:'des',
index:'des',
sortable:true,
editable:true
},
{name:'type',
index:'type',
sortable:true,
editable:true
},
{name:'status',
index:'status',
sortable:false,
editable:true
}
],
pager: '#pager1',
sortname: 'rbranch',
sortorder: 'asc',
rowNum: 100, // Only fetch 100 at a time
viewrecords: true,
scroll: 1,
sortable: true,
caption: 'Scheduling Resources'
});
$("#list1).navGrid("#pager1",
// Turn on the icons
{edit:true,
add:true,
del:true,
search:true,
refresh:true,
refreshstate:'current',
view:true
},
// Edit dialog parameters
{reloadAfterSubmit: false,
closeAfterEdit: true
},
// Add dialog parameters
{reloadAfterSubmit: true,
closeAfterAdd: true
},
// Delete dialog parameters
{reloadAfterSubmit: false},
// Search dialog parameters
{},
// View dialog parameters
{}
);
To go to page 76 I am trying this:
$("#list1").trigger("reloadGrid",[{page:76}]);
You use scroll: 1 option. It's a special virtual scrolling mode. In the mode many things work in another way or not works at all. You can try to remove the option and use standard paging.
I've been visiting this forum a lot without registering since several months ago, and I really like it. So, thanks in advance to all the members. Now I'd like to make my first question.
I've been using Jqgrid for a few time, and I've managed to have it display the rows and buttons, but now I need to do a search, a complex one, and I thought that "automatically" jqgrid would send the parameters to the server, I mean:
sField, searchField, sOper, searchOper, sValue, searchString, sFilter and/or filters
I'm not sure at all which ones it has to send, and I thought it would be just the same as it sends 'page', 'rows' and 'sord'. But I'm missing something, because, for example, I can get 'page', 'rows' and 'sord' using:
$limit = $this->getRequest()->getParam('rows', 10);
but I get nothing by using:
$params = $_REQUEST['filters']
or
$params = $this->getRequest()->getParam('sFilter');
I'm using PHP, Zend and json.
I didn't post any code because my doubt is kind of generic, but I will do it if it was needed.
I've searched a lot, and read the documentation, but I just don't see it. I will appreciate your help, thanks!
Well, I'll respond to my own question just to share. I just added 'loadonce' and it worked.
This is a version of my actual javascript code:
$(document).ready(function() {
var filtro = {"groupOp":"AND","rules":[{"field":"Col1","op":"eq","data":""},
{"field":"Col3","op":"eq","data":""}
{"field":"Col4","op":"eq","data":""}]};
$("#lista").jqGrid( {
url:'/module/controller/json-action',
datatype: "json",
postData: { filters: JSON.stringify(filtro) },
mtype: 'POST',
colNames:[, 'Col1', 'Col2','Col3','Col4'],
colModel:[
{name:'N°',index:'ID', width:60, align:"center", hidden:true},
{name:'Col1',index:'Col1', width:150, search:true, searchoptions: { sopt: ['eq'] } },
{name:'Col2',index:'Col2', width:250, align:"left", search:false},
{name:'Col3',index:'Col3', width:120, align:"left", search:true, searchoptions: { sopt: ['eq'] }},
{name:'Col4',index:'Col4', width:60, align:"center", search:true, searchoptions: { sopt: ['eq'] }}]
, rowNum:10
, rowList:[10,20,30]
, pager: '#pager'
, sortname: 'ID'
, viewrecords: true
, sortorder: "desc"
, caption:"Listado de ejemplo"
, loadonce: true
, onSelectRow: function(id) {
$("#ID").val(id);
}
, ondblClickRow: function(id) {
$("#edit").submit();
}
});
$("#lista").jqGrid(
'navGrid', '#pager', { edit:false, add:false, del:false },
{},// settings for edit
{},// settings for add
{},// settings for delete
{ multipleSearch:true/*activa la búsqueda avanzada*/,
closeAfterSearch:true, closeAfterReset:true, recreateFilter:true,
/*la función que define la búsqueda*/
onSearch: function() {}//fin onSearch
,
//the search criteria that user selected before pressing find use below code:
onClose:function() {
}//fin onClose
}
);
});//fin document ready
All I did was just to add "loadonce: true". if I remove "loadonce: true", the grid won't filter anymore.
The jqGrid's website has following code example about how to use grouping feature, it works very well.
$(document).ready(function(){
var mydata = [
{id:"1",invdate:"2010-05-24",name:"test",note:"note",tax:"10.00",total:"2111.00"} ,
{id:"2",invdate:"2010-05-25",name:"test2",note:"note2",tax:"20.00",total:"320.00"},
....
];
$("#list48").jqGrid({
data: mydata,
datatype: "local",
height: 'auto',
rowNum: 30,
rowList: [10,20,30],
colNames:['Inv No','Date', 'Client', 'Amount','Tax','Total','Notes'],
colModel:[
{name:'id',index:'id', width:60, sorttype:"int"},
{name:'invdate',index:'invdate', width:90, sorttype:"date", formatter:"date"},
{name:'name',index:'name', width:100, editable:true},
{name:'amount',index:'amount', width:80, align:"right",sorttype:"float", formatter:"number", editable:true},
{name:'tax',index:'tax', width:80, align:"right",sorttype:"float", editable:true},
{name:'total',index:'total', width:80,align:"right",sorttype:"float"},
{name:'note',index:'note', width:150, sortable:false}
],
pager: "#plist48",
viewrecords: true,
sortname: 'name',
grouping:true,
groupingView : {
groupField : ['name'],
groupDataSorted:false,
groupColumnShow:[true]
},
caption: "Grouping Array Data"
});
But if I remove:
data: mydata,
And compose the grid by using addRowData:
$('#list48').addRowData("id", mydata);
The grouping disappeared, anybody experience similar issue ? Could you please help?
Thanks!
Try calling sortGrid after addRowData. That worked for me. Syntax for sortGrid is at http://www.trirand.com/jqgridwiki/doku.php?id=wiki:methods
var sortByColumnKey = 'StartDate';
$('#grid').jqGrid('sortGrid', sortByColumnKey, true);
I too had the same issue. Just triggering 'reloadGrid' solved it for me.
$('#grid').trigger('reloadGrid');
Grouping is not taken after adding rows on $('#list48').addRowData("id", mydata);
You should re-group with new data added in grid. Try this after adding rows to grid.
$('#list48').jqGrid('groupingGroupBy', 'name', {
groupDataSorted:false,
groupColumnShow:[true]
});
I am using jqGrid for my data table solution. Below are the configuration codes.
$(function() {
$("#submitInput").click(function() {
alert("I am called...")
jQuery("#list").jqGrid({
datatype: "json",
url: "http://localhost:1201/admin/someURL.htm",
mtype:"POST",
height: "auto",
colNames:["Column 1", "Column 2", "Column 3", "Column 4", "Column 5"],
colModel:[
{name:"col1", index:"col1", sortable:true, resizable:false},
{name:"col2", index:"col2", sortable:true},
{name:"col3", index:"col3", sortable:false, resizable:false},
{name:"col4", index:"col4", sortable:true, resizable:false},
{name:"col5", index:"col5", sortable:true, resizable:false}
],
sortname:'col1',
sortorder:'asc',
pager: $('#pager'),
rowNum:10,
viewrecords: true,
rowList:[10,20,30],
caption: 'Some Grid Values',
jsonReader: {
root: "responseData",
page: "currentPage",
total: "totalPages",
records: "totalFetchedRecords",
repeatitems: true,
cell: "rowContent",
id: "rowID"
},
gridComplete: function() {
alert("Loading done...");
}
});
});
});
My JSON data is coming in the following format:
"currentPage":"1","responseData":[
{"rowContent":["Col1_Val_000001","Col2_Val_1","Col3_Val_1","Col4_Val_1","Col5_Val_1"],"rowID":"Col1_Val_000001"},
{"rowContent":["Col1_Val_000002","Col2_Val_2","Col3_Val_2","Col4_Val_2","Col5_Val_2"],"rowID":"Col1_Val_000002"}
], "totalFetchedRecords":"50","totalPages":"5"}
In my HTML, there is a button with id "submitInput" and a table with id "list".
Somehow, this data is not loaded into the grid. What is the reason?
Probably you should don't create jqGrid inside of click handle. You should do this one time outside of click handle and call jQuery("list").trigger('reloadGrid') inside of the handler. If at the beginning the data should be not loaded in the grid, you can use datatype: 'local' an the beginning. If it needed, you can makes div with jqGrid sometimes visitable and sometimes invisible using using hide() and show() jQuery functions. Inside of click handler you can change the datatype to 'json' with respect of setGridParam() and then call trigger('reloadGrid'). In a lot of situation you also change some parameters of URL before calling trigger('reloadGrid') (see Should one replace the usage addJSONData of jqGrid to the usage of setGridParam(), and trigger('reloadGrid')?), but probably you need it not in your case.