I have a jqGrid where I am trying to give the user the choice to save their own views. These views are stored in the db with all the parameters. I have around 30 columns so its impossible to fit the whole grid in one page so I have given the option to move the rows around, adjust the width, etc and then being able to save the parameters.
For this I have this code to save the whole grid in the DB
var saveLayoutDialog =
"<div title='Save Layout'>"+
"<label style='width: 100%; !important;'>Name the layout</label></br>" +
"<input type='text' name='nameOfLayout' id='nameOfLayout' placeholder='Name of Layout' style='width: 100%; !important;'>" +
"</div>";
$(saveLayoutDialog).dialog({
modal: true,
buttons: {
'OK': function () {
$.ajax({
type: 'POST',
url: Routing.generate('save_grid_parameters_homepage', { gridName: 'PODetail' }) ,
data: {
'layoutName': $("#nameOfLayout").val(),
'gridData': JSON.stringify($("#list").getGridParam())
},
success: function(data){
if(data.success == 'success')
{
}
else if(data.success == 'fail')
{
}
}
});
$(this).dialog('close');
},
'CANCEL': function () {
$(this).dialog('close');
}
}
});
This is working fine and I am able to save the data on the dB.
On the grid I have a button to change the design of the layout. So when the user clicks on the button the available layouts (previously saved in the dB) appears and user can select one and the design of the grid should change accordingly.
This is the code for the button:
.navButtonAdd("#pager",{
id: "changeDesign",
caption:"Change Design",
onClickButton: function(){
var htmlForPopup = "<div id='changeDesign' title='Change Design'>"+
"<label style='width: 100%; !important;'>SELECT A DESIGN</label>" +
"<div class='radio'>";
$.ajax({
url: Routing.generate('get_grid_layouts_homepage', { gridName: 'PODetail' }),
success: function(data){
$.each (data, function (bb) {
htmlForPopup +=
"<input type='radio' name='gridLayouts' id='"+data[bb].layoutName+"' value='"+data[bb].gridData+"' style='width: 20%; !important;'>"+data[bb].layoutName+"</br>";
});
htmlForPopup += "</div></div>";
$(htmlForPopup).dialog({
modal: true,
buttons: {
'OK': function() {
//console.log(JSON.parse($('input[name=gridLayouts]:checked').val()));
$("#list").setGridParam(JSON.parse($('input[name=gridLayouts]:checked').val())).trigger("reloadGrid");
$(this).dialog('close');
}
}
});
}
});
}
});
Problem: The desired is not working properly. The rows are not moving around and the column data moving around is not being displayed properly.
Example:
This is the ideal grid that gets loaded by default.
This is the pop up that shows up on the click of the button code show above.
On clicking on one of the options, ideally the Discount
column and the Cost
column should switch their positions with their respective data as well. But that is not happening Instead this is happening:
The data of the discount and the cost column is being switched but the title itself is not switched. Also under
Cost
(which ideally should have Discount
column's data gets converted into NaN
(which I am assuming is because of data type mismatch)
What am I doing wrong here?
EDIT 1: jqGrid version 4.8.2 and please let me know if the full jqGrid is required and I will update the question with the code.
EDIT 2: Working fiddle