Forum



11:00

08/09/2010

Hi,
i have a simple JQgrid with some data, loaded from server. Two of the columns can be modified.
Additionally a have a "save"-Button that runs through all rows and calls the saveRow-Method for posting each row to the server:
$('#safeOfferSettingsButton').click(function() {
var changedRowsArr = jQuery("#editoffer").getChangedCells('all');
addMessage("<b>SAVE: changed rows: " + changedRowsArr.length + "</b>");
// run throug all rows and send save-requests.
var rowArr = jQuery("#editoffer").getRowData();
$.each(rowArr, function(index, value){
addMessage("... saving " + value["id"]);
//jQuery('#editoffer').saveRow(value["id"], false, '<c:url value="/settings/FormSettingsServlet"/>');
//jQuery('#editoffer').jqGrid('saveRow', value["id"], checkSaveResponse, "<c:url value='/settings/FormSettingsServlet'/>");
jQuery('#editoffer').jqGrid('saveRow', value["id"] , checkSaveResponse);
}
);
});
The Method addMessage displays content in a seperate <div> for debugging. The array contains the correct data, but calling the saveRow Method does noting. It doesn't post data to the server.
Can somebody help?
Thanks.
Here's the complete code:
<!--
********************************
The grid
********************************
-->
<table id="editoffer"></table>
<script type="text/javascript">
var lastSelectedID;
jQuery("#editoffer").jqGrid(
{ url: "/myServlets/FormSettingsServlet?mode=xml", /* url for getting the data in xml format*/
datatype: "xml",
mtype:"post",
height: 250,
colNames:['No','Name', 'Visible', 'Required'],
colModel:[
{name:'id', index:'id', width:60, sortable:false, hidden:false},
{name:'name', index:'name', width:300, sortable:false, editable:false},
{name:'visible', index:'visible', width:40, sortable:false, editable:true, edittype:'checkbox', editoptions: { value:"true:false"}, formatter: booleanImageFormatter, unformat:booleanImageUnFormatter, align:'center'},
{name:'required', index:'required', width:40, sortable:false, editable:true, edittype:'checkbox', editoptions: { value:"true:false"}, formatter: booleanImageFormatter, unformat:booleanImageUnFormatter, align:'center'}],
/**
* Do not start edit. Just negate the current value.
* This is done in order to change checkbox-values by one click:
* Process only clicks on column-index 2 and 3.
*/
onCellSelect: function(rowid, iCol, cellcontent, e){
addMessage("trying to change selection... rowid:"+rowid+" last id:" + lastSelectedID + " ->iCol: " + iCol);
var colName = "";
if (iCol == 2){colName ="visible"; }
else if (iCol == 3){colName ="required";}
if (iCol != ""){
// get the row
var tRowDataArray = jQuery('#editoffer').getRowData(rowid);
addArrMessage(tRowDataArray);
addMessage("<b>current Value: \"" + tRowDataArray[colName] + "\"</b>");
// invert the value
tRowDataArray[colName] = "" + ("true" != tRowDataArray[colName]);
addMessage("<b style='color:#aabbff;'>new Value: \"" + tRowDataArray[colName] + "\"</b>");
// Set date to refresh.
jQuery('#editoffer').setRowData(rowid,tRowDataArray);
}
},
editurl: "/myServlets/FormSettingsServlet?mode=xml",
multiselect: false,
viewrecords: true, rowNum:200, autowidth: true,
caption: "Testdata" });
/**
* Display an image that looks like a checkbox
*/
function booleanImageFormatter (cellvalue, options, rowObject){
var trimmed = jQuery.trim(cellvalue);
if (trimmed == "true"){
return "<div class=\"centered-cell dummy-check\"><span class=\"solo-icons solo-icon-check\" onMouseOver> </span></div>";
}
else{
return "<div class=\"centered-cell dummy-uncheck\"><span class=\"solo-icons solo-icon-uncheck\"> </span></div>";
}
}
/**
* Return the booleanvalue of the formatted content
*/
function booleanImageUnFormatter (cellvalue, options, cellobject){
var imgID;
try{
imgID = $(cellobject.firstChild).hasClass("dummy-check");
}
catch(e){
alert(e);
}
// important to return a string-value
return "" + imgID;
}
</script>
<!--
********************************
Submitt-button
********************************
-->
<input type="button" name="button" value="Speichern" id="safeOfferSettingsButton" class="ui-button ui-state-default ui-corner-all ui-button-text-only">
<script type="text/javascript">
$('#safeOfferSettingsButton').click(function() {
var changedRowsArr = jQuery("#editoffer").getChangedCells('all');
addMessage("<b>SAVE: changed rows: " + changedRowsArr.length + "</b>");
// run throug all rows and send save-requests.
var rowArr = jQuery("#editoffer").getRowData();
$.each(rowArr, function(index, value){
addMessage("... saving " + value["id"]);
//jQuery('#editoffer').jqGrid('saveRow', value["id"], checkSaveResponse, "/myServlets/FormSettingsServlet");
//jQuery('#editoffer').saveRow(value["id"], false, '/myServlets/FormSettingsServlet');
jQuery('#editoffer').jqGrid('saveRow', ''+value["id"] , checkSaveResponse);
}
);
});
function checkSaveResponse(result) {
if (result.responseText==""){
addMessage("<span style:\"color:red;\">update is missing</span>");
}
else{
addMessage("<span style:\"color:green;\">success</span>");
}
return true;
}
</script>
<!--
********************************
This is an area for
debug-messages
********************************
-->
<div id="messages" style="font-size:10px; border : solid 2px #555555; background : #000000; color : #bbbbbb; padding : 4px; width : 100%; height : 300px; overflow : auto;"> </div>
<input type="button" name="button" value="clear" id="clearConsoleMessages" class="ui-button ui-state-default ui-corner-all ui-button-text-only">
<script type="text/javascript">
function addMessage(aMessage){
$('#messages').html($('#messages').html() + aMessage + "<br>");
}
function addArrMessage(aArrayData){
var MessageString = "";
$.each(aArrayData, function(key, val){
MessageString = MessageString + key + ": " + val + ", ";
});
addMessage( " -> " + MessageString);
}
$('#clearConsoleMessages').click(function(){
$('#messages').html("");
});
</script>
14:34

08/09/2010

My Problem is solved.
I had to Edit the row before i save it. I found this solution by debugging the code of jqGrid (hard work ;-)).
Maybe it is a dirty workaround but i've found no better solution.
So instead fo calling
now i call
jQuery('#editoffer').saveRow( rowID, checkSaveResponse, "<c:url value='/settings/FormSettingsServlet'/>", {}, null, handleSaveErrors);
Maybe this post will help someone else too.
16:45

24/08/2011

I am using thus jQuery grid plugin in my rails application.
I also want to use a single 'Submit' button to update the modified records.
I have added the above code snippet to my code, but I got an error in the line
$.each(rowArr, function(index, value)
Error I got in firebug is '$.each is not a function '.
Please help me.
Most Users Ever Online: 715
Currently Online:
92 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
OlegK: 1255
markw65: 179
kobruleht: 144
phicarre: 132
YamilBracho: 124
Renso: 118
Member Stats:
Guest Posters: 447
Members: 11373
Moderators: 2
Admins: 1
Forum Stats:
Groups: 1
Forums: 8
Topics: 10592
Posts: 31289
Newest Members:
, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66