I want to implement multiple search with boolean data.
Does jqGrid able to make search with dropdown?
In mysql table, value for accredited field is boolean (0/1).
I am showing boolean value in presentation table is "not accredited or accredited".
And I want to search through this value. So, as picture shown above, we can pick dropdown which accredited or not accredited instead of type 0 or 1.
What you need to do is just usage of stype: "select" property in definition of accredited column in colModel and definition of searchoptions which corresponds you data. For example
stype: "select",
searchoptions: { sopt: ["eq", "ne"], value: "0:not accredited;1:accredited" }
Related
There is a textbox control in one column in my jqgrid. When value is entered in this textbox in a row , it should compare that value from another column (which is non editable) and show error when the values are not equal.
From the wiki in Here
You can see the solution I created in JsFiddle
To see it working try to edit lastname cell and it will throw an error if it does not match firstname in the row (unrealistic but just for illustration purposes)
Use beforeSaveCell
afterSaveCell: function(rowid,name,val,iRow,iCol) {
alert("alert1!");
},
beforeSaveCell: function(rowid,name,val,iRow,iCol) {
// Just to get the current row b/se it is not available in custom_func
currentRow= rowid;
},
AND add editrules to your cell to be edited and validated
{name:'lastname', index:'lastname', width:90, editable: true , "editrules":{"custom":true,"custom_func":validateText}},
I have a simple jqgrid.
colModel: [ { name: 'CatId', index: 'CatId', width: 30, align: 'left' }, ...
What I want to do is turn a column into a hyperlink like this example I find on google:
formatoptions:{baseLinkUrl:'someurl.php', addParam: '&action=edit'}
However I want to put the CatId as the parameter, eg:
formatoptions:{baseLinkUrl:'someurl.php', addParam: '&action=<CatId>'}
I can't seem to find any examples of how to do this, other than possibly just hooking into the loadcomplete event and going through and manually updating every row. Is there a nice way to solve this?
The URL used by formatter: "showlink" will be constructed using formatoptions which could be baseLinkUrl, showAction, idName and addParam. The formatter "showlink" uses rowid (the id attribute of <tr> elements of the grid) for constructing the URL. The URL will be built as
baseLinkUrl + showAction + '?' + idName + '=' + rowId + addParam
So the main problem is whether the value of CatId column be used or can be used as the rowid. If you would use key: true option to the definition of CatId column then jqGrid will use the value from CatId as rowid and you could use
formatter: "showlink", formatoptions: { baseLinkUrl: "someurl.php", idName: "action" }
If the value of CatId column can't be used as rowid then I would recommend you to use formatter: "dynamicLink" instead (see jQuery.jqGrid.dynamicLink.js here). I described it in the answer.
OK, I am having an issue with the filter toolbar retaining the filter values after clicking on the Refresh button at the bottom of the grid.
I have looked at numerous examples that do exactly that, clear the top filter toolbar fields to the default state (in the case of select list, to the first item in the list "Select..."), but I do not see any obvious difference between that code and mine
Values are being loaded into the filter toolbar drop down boxes via JSON request, and on selecting an item in the list the grid filters to the appropriate data.
The only thing that is not working is that the filter drop-down(s) do not clear the selected item upon clicking refresh grid.
Any ideas?
Not sure what code would help to post at this point, so I will post upon request
Justin
Well, I have answered my own question :)
The issue turned out to be related to naming convention for column names and indexes.
Example:
Before fix:
{ name: ClientId', index: 'ClientOrganization.Client.ClientId', width: '125', stype: 'select', searchoptions: { sopt: ['eq'], dataUrl: '#Url.Action("GetClientListForFilter")'} },
After fix:
{ name: 'ClientOrganization.Client.ClientId', index: 'ClientOrganization.Client.ClientId', width: '125', stype: 'select', searchoptions: { sopt: ['eq'], dataUrl: '#Url.Action("GetClientListForFilter")'} },
Basically the name needed to be the same as the index to properly refresh. Not sure if this is expected behavior or not, but the fix works. ;)
Justin
I.e. I want the field name "Firstname" to have an asterisk in it to denote a compulsory e.g. "*Firstname", but I don't want the main grid column name to have asterisk in it too.
Clicking the Edit button pops up a form with the asterisk it in, but this also appears on the Grid when viewing the resultset.
Can someone advise on a way around this?
Thanks.
This is what I've currently got that doesn't solve my problem.
colNames: ['*Firstname']
colModel:[{ name: 'Firstname', index: 'Firstname', label: 'Firstname', width: 150, editable: true, editrules: { required: true} }]
If you set some prefix or suffix for the column name in the Edit form you should use corresponding formoptions instead of the colNames or label property in the colModel.
I am using jqGrid v 4.0 in my application to display tabuler data with Inline edit feature. One of the column in the Grid is a type of "Select". I have populated this select with following server side code:
//get all Departments
HRDept = $.ajax({
url: '../../PerformanceReview/GetHRDepartments/',
async: false,
success: function(data, result) {
if (!result)
alert('Failure to retrieve the HR Departments.');
}
}).responseText;
I have populated the Grid column with following sysntax:
name: 'HRDepartment', index: 'Department', align: 'left', editable: true, edittype: 'select', editoptions: {value: HRDept}
But on click of edit button (inline), it shows dropdown on on top of cell but the value is not equal to current cell value. it is always first value of drop down. I had compared the text which i am populating while loading Grid with the text of Dropdown and they are matching.
Could some one help me to set dropdown value similar as cell value.
Your edit options look wrong, it should be "value:text;" and the value should match your data results.
{ ... editoptions: {value: "HRDept:HR Department;" }}
You can checkout the demo of Row Edition -> Input Types at the jqGrid Demo site., which includes a dropdown list edit cell.
If you get the select values from the server you should use dataUrl option of the editoptions instead of value. Then the jqGrid will make the Ajax request at the beginning of the editing and fill the select element with the server response. It is important to understand that the server response should be in another form:
<select>
<option value='101 - Equity Partners'>101 - Equity Partners</option>
…
</select>
If you have already the code on the server which provide the information in another format and you can't change the server code you can define additional buildSelect function which get as the parameter the server response and should return the data in the above format ('...'). See UPDATED part of the answer for the code example.