Line 15 of client server code is wrong.
Correction:
cm = colM square bracket i square bracket
Hi,
I wanted it all dynamic. The proyect have a text field with select SQL, when you click execute button generate table jqgrid.
In server side (JSON):
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
case Types.TIMESTAMP: infCol.put(VAR_FORMATTER, "date"); infCol.put(VAR_FORMAT_USER, "date"); // Datepicker StringBuilder funcionFecha = new StringBuilder(); funcionFecha.append(" function (element) { $(element).datepicker({ "); funcionFecha.append(" id: '" + name + "_datePicker' "); funcionFecha.append(","); funcionFecha.append(" dateFormat: '" + "dd-mm-yy" + "', "); funcionFecha.append(" onSelect: function(datetext){ seleccionFechaDP(this,datetext); }"); funcionFecha.append("}); }; "); editOptionsCol.put(VAR_DATA_INIT, funcionFecha.toString()); editOptionsCol.put(VAR_MAX_LENGTH, 19); // Opciones del formato formatOptions.put(VAR_SRC_FORMAT, "U/1000"); formatOptions.put(VAR_NEW_FORMAT, "d-m-Y H:i:s"); // Add objects infCol.put(VAR_EDITRULES, editRulesCol); infCol.put(VAR_EDITOPTIONS, editOptionsCol); infCol.put(VAR_FORMAT_OPTIONS, formatOptions); ... // Return result // infCol object into json with key colModel |
In client server:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
... $.ajax({ type : "POST", url : "executeSQL", data : form.serialize(), dataType : "json", success : function(result) { colD = result.colData; colN = result.colNames; colM = result.colModel; var i, cm; for (i = 0; i < colM.length; i++) { cm = colM<em class="d4pbbc-italic"></em>; if (cm.hasOwnProperty("format_user")&& functionsMapping.hasOwnProperty(cm.format_user)) { cm.formatter = functionsMapping[cm.format_user]; } } $(tablaResul).jqGrid('GridUnload'); $(tablaResul).jqGrid({ datatype : 'local', colNames : colN, colModel : colM, data : colD.rows, rowNum : 20, height : 250, autowidth : true, shrinkToFit : false, pager : tablaPie, viewrecords : true, loadonce : true }); ... var functionsMapping = { // here we define the implementations of the custom formatter which we use "date" : function(cellValue, opts, rowObject) { var cellDisplayValue = ''; try { var funcExec = 'opts.colModel.editoptions.dataInit=' +opts.colModel.editoptions.dataInit; eval(funcExec); } catch (err) { if(numError == 0){ alert("Error (functionsMapping): " + err.message); numError++; } } var operacion = rowObject.oper; if(operacion == null){ if(cellValue){ if(isNaN(cellValue)){ // Realizada esta opcion cuando se cancela una modificacion. cellDisplayValue = cellValue; }else{ var op = $.extend({}, $.jgrid.formatter.date); if (opts.colModel.formatoptions != undefined) { op = $.extend({}, op, opts.colModel.formatoptions); } var scrFormat = opts.colModel.formatoptions.srcformat; var newFormat = opts.colModel.formatoptions.newformat; cellDisplayValue = $.jgrid.parseDate(scrFormat, cellValue, newFormat); } } } else if(operacion = "edit"){ cellDisplayValue = cellValue; } return cellDisplayValue; } }; |
Code with JQGrid 4.7.0 and JQuery 1.8.2
Thanks for your reply.
I have fixed problem.
I will show the new code to guriddo people when it is all right.
Copyright 2014 TriRand LtdAll Rights ReservedRSS
Back to Top