jQuery(document).ready(function(){ var lastsel; //used for Double Click Row Selection. jQuery("#grid").jqGrid({ url:'/jobs/build_jobs_json/', datatype: "json", mtype: 'GET', colNames:[ //'id', 'created','Job Number','customer','Customer Ref','supplier_reference','date_order_received', 'date_order_placed_on_principle','date_scheduled_ex_works','date_order_sent_to_customer','domestic_freight_paid_by', 'sale_category','shipment_category','comments','company_gross_sales_aud','net_sales_aud','gross_profit_aud','ato_exchange_rate', 'gst','currency_id','gst_amount','gross_commisions','invoiced_amount_inc_gst','net_export_sales_aud', 'gross_profit_exports_aud','gp_percent','gross_australian_sales_foreign_currency','net_australian_sales_foreign_currency', 'gross_profit_value_australian_sales_foreign_currency','gross_export_sales_foreign_currency','net_export_sales_foreign_currency', 'gross_profit_value_after_discount_exports_foreign_currency','gross_commissions','net_commissions' ], jsonReader : { root: "rows", page: "page", total: "total", records: "records", repeatitems: true, cell: "cell", id: "id" }, colModel:[ /*{ name:'id', index:'id', width:200, editable:false },*/ { name:'created', index:'created', width:100, editable:false }, { name:'title', index:'title', width:100, editable:false }, { name:'customer', index:'customer', width:400, editable:false }, { name:'customer_order_number', index:'customer_order_number', width:100, editable:true }, { name:'supplier_reference', index:'supplier_reference', width:100, editable:true }, { name:'date_order_received', index:'date_order_received', width:200, editable:true, sorttype:"date" }, { name:'date_order_placed_on_principle', index:'date_order_placed_on_principle', width:200, editable:true, sorttype:"date" }, { name:'date_scheduled_ex_works', index:'date_scheduled_ex_works', width:200, editable:true, sorttype:"date" }, { name:'date_order_sent_to_customer', index:'date_order_sent_to_customer', width:200, editable:true, sorttype:"date" }, { name:'domestic_freight_paid_by', index:'domestic_freight_paid_by', width:200, editable:true, edittype:"select", editoptions:{ value:"Customer:Customer;CMC:CMC" } }, { name:'sale_category', index:'sale_category', width:50, editable:true }, { name:'shipment_category', index:'shipment_category', width:200, editable:true }, { name:'comments', index:'comments', width:200, editable:true, edittype:"textarea", }, { name:'company_gross_sales_aud', index:'company_gross_sales_aud', width:200, editable:true }, { name:'net_sales_aud', index:'net_sales_aud', width:200, editable:true }, { name:'gross_profit_aud', index:'gross_profit_aud', width:200, editable:true }, { name:'ato_exchange_rate', index:'ato_exchange_rate', width:200, editable:true }, { name:'gst', width:200, editable:true }, { name:'currency_id', index:'currency_id', width:200, editable:true }, { name:'gst_amount', index:'gst_amount', width:200, editable:true }, { name:'gross_commisions', index:'gross_commisions', width:200, editable:true }, { name:'invoiced_amount_inc_gst', index:'invoiced_amount_inc_gst', width:200, editable:true }, { name:'net_export_sales_aud', index:'net_export_sales_aud', width:200, editable:true }, { name:'gross_profit_exports_aud', index:'gross_profit_exports_aud', width:200, editable:true }, { name:'gp_percent', index:'gp_percent', width:200, editable:true }, { name:'gross_australian_sales_foreign_currency', index:'gross_australian_sales_foreign_currency', width:200, editable:true }, { name:'net_australian_sales_foreign_currency', index:'net_australian_sales_foreign_currency', width:200, editable:true }, { name:'gross_profit_value_australian_sales_foreign_currency', index:'gross_profit_value_australian_sales_foreign_currency', width:200, editable:true }, { name:'gross_export_sales_foreign_currency', index:'gross_export_sales_foreign_currency', width:200, editable:true }, { name:'net_export_sales_foreign_currency', index:'net_export_sales_foreign_currency', width:200, editable:true }, { name:'gross_profit_value_after_discount_exports_foreign_currency', index:'gross_profit_value_after_discount_exports_foreign_currency', width:200, editable:true }, { name:'gross_commissions', index:'gross_commissions', width:200, editable:true }, { name:'net_commissions', index:'net_commissions', width:200, editable:true }, ], // viewrecords: true, sortname: 'id', sortorder: "asc", rowNum: 50, height: '100%', caption:"Jobs", editurl:"/jobs/ajax_edit", onSelectRow: function(rowid){ if(typeof(lastsel) != undefined) { if(rowid && rowid!==lastsel){ $(this).jqGrid('saveRow',lastsel); $(this).jqGrid('editRow', rowid, true, pickdates); } } lastsel = rowid; } }); $("#editButton").click(function(){ var gr = jQuery("#grid").jqGrid('getGridParam','selrow'); if(gr != null) { jQuery("#grid").jqGrid('editRow', gr, true, pickdates); } }); function pickdates(id){ jQuery("#"+id+"_date_order_received","#grid").datepicker({ dateFormat:"yy-mm-dd" }); jQuery("#"+id+"_date_order_placed_on_principle","#grid").datepicker({ dateFormat:"yy-mm-dd" }); jQuery("#"+id+"_date_scheduled_ex_works","#grid").datepicker({ dateFormat:"yy-mm-dd" }); jQuery("#"+id+"_date_order_sent_to_customer","#grid").datepicker({ dateFormat:"yy-mm-dd" }); } });