Edit form on JQGrid and ASP.NET MVC 2 - asp.net-mvc-2

I am having an issue on JQgrid when I select a row and press edit button. The problem is that I want a modal edit-form and it apears at the top of the page, but when I click on it, it close.
I review the JQgrid docs and search for examples but I can't make it work. I am using ASP.NET MVC 2 and JQgrid 1.4.1 and I attached the files JqDnr and Jqmodal.
<script type="text/javascript">
var lastsel;
jQuery(document).ready(function() {
jQuery("#list").jqGrid({
url: '/Home/DynamicGridData/',
datatype: 'json',
mtype: 'GET',
colNames: ['Id', 'Nombre', 'Sponsor', 'Fecha de Evaluacion', 'Fecha Prevista de Fin', 'Planta', 'Sector', 'LOTO?', 'Trabajo en Altura?', 'Espacio Confinado?', 'Caliente?', 'Amianto?', 'Observaciones'],
colModel: [
{ name: 'Id', index: 'Id', width: 40, align: 'left', editable: false },
{ name: 'Nombre', index: 'Nombre', width: 200, align: 'left', editable: true },
{ name: 'Sponsor', index: 'Sponsor', width: 80, align: 'left', editable: true, edittype: "select", editoptions: { size: 71} },
{ name: 'Fecha de Evaluacion', index: 'FechaEvaluacion', width: 90, align: 'left', editable: true },
{ name: 'Fecha Prevista de Fin', index: 'FechaPrevistaFin', width: 90, align: 'left', editable: true },
{ name: 'Planta', index: 'Planta', width: 70, align: 'left', editable: true },
{ name: 'Sector', index: 'Sector', width: 70, align: 'left', editable: true },
{ name: 'LOTO?', index: 'PermisoLOTO', width: 50, align: 'left', editable: true, formatter: "checkbox" },
{ name: 'Trabajo en Altura?', index: 'PermisoTrabajoAltura', width: 50, align: 'left', editable: true, formatter: "checkbox" },
{ name: 'Espacio Confinado?', index: 'PermisoEspacioConfinado', width: 50, align: 'left', editable: true, formatter: "checkbox" },
{ name: 'Caliente?', index: 'PermisoCaliente', width: 50, align: 'left', editable: true, formatter: "checkbox" },
{ name: 'Amianto?', index: 'PermisoAmianto', width: 50, align: 'left', editable: true, formatter: "checkbox" },
{ name: 'Observaciones', index: 'Observaciones', width: 200, align: 'left', editable: true}],
pager: jQuery('#pager'),
rowNum: 10,
rowList: [5, 10, 20, 50],
sortname: 'Id',
sortorder: "desc",
viewrecords: true,
imgpath: '/scripts/themes/sand/images',
caption: 'Tareas'
}).navGrid("#pager", { edit: true });
});
</script>
Tareas
So, any help will be very helpfull. Thanks!

I can not reproduce your probelm (see the test here), but I can definitively say you that you have to change the values from the name property from the colModel. The name property will be used as the property name. It build additionally the ids of different elements in the Edit form. The id ementens like
id="Fecha Prevista de Fin"
id="tr_Fecha Prevista de Fin"
id="Amianto?"
id="tr_Amianto?"
and so on are bad. You can use Developer Tools of IE for example (press F12 in IE) to examine the ids used in the Edit form of your current code. I strictly recommend you to use in the name property only characters from the set [a-zA-Z0-9] and start the name with a letter. No blanks inside of the name is permitted (see here and here).
By the way the parameter imgpath is deprecated since many jqGrid releases and you should remove it.

Related

MUI Datagrid rendercell getValue return undefined

Since I pushed my code on production, I cant call anymore getValue inside renderCell
Environnement is the same as dev by the way
Here is the columns def:
const columns = [
{
field: 'edit',
headerName: 'Edit',
sortable: false,
width: 78,
renderCell: (params) => (
<div>
<EditProduct defaultCats={props.defaultCats} prodId={params.getValue('id')} productIdGL={params.getValue('productId')} />
</div>
),
align: "left",
},
{
field: 'active',
headerName: 'Off / On',
width: 104,
renderCell: (params) => (
<div><CustomSwitch
checked={Boolean(params.value)}
onChange={() => myswitch(params.getValue('id'), Boolean(params.value))}
name="switch-"
inputProps={{ 'aria-label': 'primary checkbox' }}
></CustomSwitch>
</div>
),
align: "left",
},
{ field: 'category_name', headerName: 'Catégorie', width: 120 },
{ field: 'item_name', headerName: 'Nom du produit', width: 220 },
{
field: 'price',
headerName: 'Prix de vente',
type: 'number',
width: 140,
},
{
field: 'profit',
headerName: 'Profit par vente',
type: 'number',
width: 160,
alt: 'Test'
},
{ field: 'type', headerName: 'Type', width: 90 },
{ field: 'id', headerName: '#', width: 80 },
];
Error:
Unhandled Runtime Error
TypeError: Cannot read property 'undefined' of undefined
Any help appreciate since this bug occur only on production
mui-core: 4.11.4
mui-datagrid: 4.0.0-alpha.26
params.getValue(params.id, 'id') || ''
Instead of
params.getValue('id')

comments between form fields in ext.js 2.3

I am new to ext.js and this may seem easy to some of you but not to me.
I have a form that is build with ext.js version 2.3. I am trying to place comments between the form fields. I mean the following:
inputLabel1: text form input
commentLabel: some text
inputLabel2: text form field
I am having difficulty with the second line above. I don't need it to be an input field - just a label and some text next to it, which are aligned with the form labels and input fields on the rest of the rows.
Input fields are defined as follows:
var formParts =
this.formParts = [];
var receiptAmount = new Ext.Form.NumberField( {
id: 'receiptAmount',
name: 'receiptAmount',
cls:'inputNoRightBorder ',
fieldLabel: messages.amount,
allowNegative: true,
hideLabel: false,
decimalSeparator: messages.decimalSeparator,
decimalPrecision: 2,
groupingSeparator: messages.groupingSeparator,
value: 0,
labelSeparator: messages.asteriskLineBreaker
} );
Then they are placed in containers:
var grossAmount = {
border: false,
layout: 'column',
labelWidth: 190,
cls: 'labelStyle',
border: true,
baseCls: 'ourPanel',
items: [
{
id: 'receiptAmountContainer',
border: false,
layout: 'form',
items: [receiptAmount]
},
{
id: 'receiptCurrencyContainer',
border: false,
layout: 'form',
items: [receiptCurrency]
}
]
};
The latter are placed in field sets:
var receiptFinancialData = {
id: "receiptFinancialData",
border: false,
layout: 'column',
labelWidth: 120,
cls: 'column-style',//'#background-color: #DFE8F6',
border: true,
baseCls: 'ourPanel',
height: 50,
title: messages.taxRate + ':',
header: false,
items: [
receiptExchangeRateMirror,
receiptExchangeAmountMirror,
{
border: false,
layout: 'form',
items: [grossAmount]
},
{
border: false,
layout: 'form',
cls: 'labelStyle',
items: [taxRate]
}
]
};
And again:
var singleLineItemContainer = new Ext.form.FieldSet( {
id: 'singleLineItemContainer',
name: 'singleLineItemContainer',
cls: 'singleLineItemContainer',
isActive: true,
hideLabel: true,
height: 'auto',
items: [
referenceCurrency,
receiptType,
entertainmentType,
receiptFinancialData
]
} );
And again:
var lineItemsContainer = new Ext.form.FieldSet( {
id: 'lineItemsContainer',
name: 'lineItemsContainer',
header: false,
border: false,
height: 'auto',
anchor: '100%',
items: [
toggleSingleMultyContainer,
singleLineItemContainer,
multipleLineItemsContainer,
currencyAndExchangeSet
]
} );
And again:
var generalData = new Ext.form.FieldSet( {
id: 'generalReceiptData',
name: 'generalReceiptData',
header: false,
border: false,
height: 'auto',
anchor: '100%',
items: [
receiptClass,
{
id: 'generalDataReceiptCountryAndDate',
border: false,
layout: 'column',
labelWidth: 120,
cls: 'column-style',//'#background-color: #DFE8F6',
border: true,
baseCls: 'ourPanel',
height: 50,
header: false,
items: [
{
id: 'generalDataReceiptDate',
border: false,
layout: 'form',
cls: 'dateField',
items: [receiptDate]
},
{
id: 'generalDataReceiptCountry',
border: false,
layout: 'form',
items: [receiptCountry]
}
]
},
receiptDateString,
receiptDescription,
isCompanyPaid,
lineItemsContainer
]
} );
The code above is placed in
Ext.extend( receiptForm, Ext.form.FormPanel,{
initComponent: function(){
above code
}
}
There's multiple ways to do this I'm sure. Here's a quick way to sorta hack it with css and readOnly fields
fiddle
items: [{
fieldLabel: 'inputLabel1',
}, {
fieldLabel: 'commentLabel',
readOnly:true,
style:'background: transparent;border: none;',
value:'some text',
}, {
fieldLabel: 'inputLabel2',
}],
This page has some nice ext 2.3 examples, but why not learn with a newer version?

ExtJS form sended twice

I have a form with search (filtering) fields like this:
xtype: 'form',
id: 'searchPanel',
title: 'Search',
collapsible: true,
bodyPadding: 10,
height: 210,
buttonAlign: 'left',
defaults: {
width: 400,
labelWidth: 120,
allowBlank: true,
enableKeyEvents: true
},
layout: {
type: 'table',
columns: 2
},
items: [
{
xtype: 'textfield',
name: 'txtFltrSiteName',
fieldLabel: 'Site name or alias',
id: 'txtFltrSiteName'
},
{
xtype: 'textfield',
name: 'txtMonthTraffic',
fieldLabel: 'Month traffic',
id: 'txtMonthTraffic',
style: 'margin-left: 100px;'
},
{
xtype: 'combo',
id: 'ddlFltrPM',
name: 'ddlFltrPM',
fieldLabel: 'Project manager',
displayField: 'display_name',
valueField: 'user_id',
editable: false,
store: new storeOfUsers({ filters: [{ property: 'user_group_code', value: 'projectmanager', exactMatch: true }] })
},
// and many other fields below
But when i click on search button, i have two post request. One - with filter in it, second is without.
My code for send button action:
xtype: 'button',
id: 'btn_srch_set',
text: 'Searh',
margin: '10 7 0 0',
width: '',
handler: function() {
var filters = new Array();
var site_name = Ext.getCmp('txtFltrSiteName').getValue();
if(site_name.length > 0)
filters.push({dataIndex: 'site_name', type: 'string', value: site_name});
var project_name = Ext.getCmp('txtFltrProjectName').getValue();
if(project_name.length > 0)
filters.push({dataIndex: 'project_name', type: 'string', value: project_name});
var pm = Ext.getCmp('ddlFltrPM').getValue();
if(pm && pm > 0)
filters.push({dataIndex: 'project_manager_id', type: 'int', value: {'eq':pm}});
// many other fields
listOfSites.filters.removeAll();
if(filters.length > 0)
listOfSites.filters.addFilters(filters);
listOfSites.store.load();
}
P.S.
When I overwrite in search button handler function this line:
filters.push({dataIndex: 'project_manager_id', type: 'string', value: pm});
Evrything is ok and there is only one request, so problem might be here. But i'm stuck and have no idea why it works such way.
Thanks for any help,
Stanislav.
UPD*
var filters = {
ftype: 'filters',
// encode and local configuration options defined previously for easier reuse
encode: true, // json encode the filter query
local: false,
filters: [{
type: 'string',
dataIndex: 'site_name'
}, {
type: 'date',
dataIndex: 'startdate'
}, {
type: 'string',
dataIndex: 'project_name'
// more fields below
Try following
if(filters.length > 0)
listOfSites.filters.addFilters(filters);
else
listOfSites.store.load();
addFilters() may already call sync()

ExtJS: Removing and Readding a FormPanel into a Window

I'm having a problem where I would like to remove a FormPanel from a Window.
Here is my Form which is being loaded in a Window:
myForm = new Ext.FormPanel({
frame: true,
width: '100%',
id: 'myform',
layout: 'form',
autoHeight: true,
autoDestroy: false,
region: 'center',
monitorValid: true,
items: [{
xtype: 'textfield',
id: 'mytextfield',
fieldLabel: 'My Label',
}]
});
MyWindow = new Ext.Window({
title: 'MyWindow',
layout: 'auto',
resizable: false,
width: 717,
autoheight:true,
id:'mywindow',
closeAction:'hide',
closable: true,
items:[Ext.getCmp("myform")]
});
Now I want to remove this form and have to show another form, and I'm doing like this somewhere else:
MyWindow.removeAll();
MyWindow.add(Ext.getCmp("myAnotherForm"));
But this gives me error "Uncaught TypeError: Cannot read property 'events' of undefined" in ext-all-debug.js.
Is there anything, I'm missing here ?
Thanks.
You can remove the form and add another form by using the following code:
Ext.onReady(function() {
var btn = new Ext.Button({
id : 'button',
width : 100,
height : 30,
text : 'click me',
listeners : {
click : function(){
var myanother = myAnotherForm;
var anotherbtn = btn1;
Mywindow.removeAll();
Mywindow.add(myanother);
Mywindow.add(anotherbtn);
Mywindow.doLayout();
}
}
});
var btn1 = new Ext.Button({
id : 'button1',
width : 100,
height : 30,
text : 'Another button'
});
myAnotherForm = new Ext.FormPanel({
frame: true,
width: '100%',
id: 'myanotherform',
layout: 'form',
autoHeight: true,
autoDestroy: false,
region: 'center',
monitorValid: true,
items: [{
xtype: 'textfield',
id: 'mytextfield',
fieldLabel: 'My Another Label',
}]
});
myForm = new Ext.FormPanel({
frame: true,
width: '100%',
id: 'myform',
layout: 'form',
autoHeight: true,
autoDestroy: false,
region: 'center',
monitorValid: true,
items: [{
xtype: 'textfield',
id: 'mytextfield',
fieldLabel: 'My Label',
}]
});
var Mywindow = new Ext.Window({
title: 'MyWindow',
layout: 'auto',
resizable: false,
width: 317,
autoheight:true,
id:'mywindow',
closeAction:'hide',
closable: true,
items : [myForm,btn]
});
Mywindow.show();
});
The working sample for the above is follows:
http://jsfiddle.net/kesamkiran/MVewR/1/
* Click on 'click me' button then you will get the another form with another button.If you want to change only form,then you can remove the button.

Passing variables through URL in Jqgrid to controller in mvc

How do I pass values from url to Jqgrid, the issue is the Jqgrid needs to be loaded based on edit link on previous page, and we have the URL like:
http://localhost:49771/Search/EditSearchResults?id=ID_HelpTopics&action=edit
I need to be able to use this id in URL for populating the grid data, so I need to pass this value through grid to controller to get the results and the grid I have is like:
$("#list").jqGrid({
url: '<%= Url.Action("EditSearchResults", new {controller = "JSonData" }) %>',
datatype: 'json',
colNames: ['Language', 'ID'],
colModel: [
{ name: 'Language', index: 'Language', editable: false, width: 40, align: 'left', sortable: false },
{ name: 'ID', index: 'ID', width: 40, editable: true, edittype: "text", align: 'left', editoptions: { size: 5, maxlength: 30 }, sortable: false }, ],
editurl: '<%= Url.Action("EditSearchResults", new {controller = "JSONData"}) %>',
pager: '#pager',
//autowidth: true,
width: "500",
autowidth: true,
rowNum: 20,
height: "200",
loadonce: false,
rowList: [5, 10, 20, 50],
recordtext: "View Records {0} - {1} of {2}",
emptyrecords: "No records to view",
loadtext: "Loading...",
pgtext: "Page {0} of {1}",
sortname: 'Results',
sortorder: "desc",
viewrecords: true,
scroll: false,
loadonce: false,
caption: 'Edit Search Results',
ondblClickRow: function (id) {
if (id != null) {
jQuery('#grid').jqGrid('restoreRow', lastsel);
jQuery('#list').jqGrid('saveRow', id);
jQuery('#list').jqGrid('editRow', id, true, false, processEdit);
lastsel = id;
}
}
});
});
How can use the current URL to pass id to controller to populate jqgrid, How should the controller and jqgrid should be like? Any ideas?
Url.Action will take a anonymous object as a parameter set
url: '<%= Url.Action("EditSearchResults",
new {controller = "JSonData" },
new {id = Request.Params[id] }) %>',
However it would be preferable to make that part of your model than depending on the Request.