Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 10th, 2012  |  syntax: None  |  size: 6.46 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Send row_id of main jqgrid to add event of subgrid
  2. <script type="text/javascript">
  3.     $(document).ready(function () {
  4.         $('#jqgFactors').jqGrid({
  5.             //url from wich data should be requested
  6.             url: '@Url.Action("GetFactors")',
  7.             //type of data
  8.             datatype: 'json',
  9.             //url access method type
  10.             mtype: 'POST',
  11.             //columns names
  12.             colNames: ['id', 'category', 'question type', 'question', 'tooltip text', 'xdata', 'warningexception'],
  13.             //columns model
  14.             colModel: [
  15.                         { name: 'id', index: 'id', align: 'left', editable: false, width: '40px', fixed: true, key: true },
  16.                         { name: 'categoryid', index: 'categoryid', align: 'left', editable: true, edittype: 'select', width: '80px', fixed: true, editoptions: { value: { 1: 'Departure', 2: 'Pilot', 3: 'Product', 4: 'Flight', 5: 'Destination'} }, editrules: { required: true} },
  17.                         { name: 'type', index: 'type', align: 'left', editable: true, edittype: 'select', width: '100px', fixed: true, editoptions: { value: { 1: 'RadioButton List', 2: 'DatePicker'} }, editrules: { required: true} },
  18.                         { name: 'questiontext', index: 'questiontext', align: 'left', editable: true, edittype: 'textarea', width: '200px', fixed: true, editoptions: { rows: '5', cols: '40' }, editrules: { required: true} },
  19.                         { name: 'tooltip', index: 'tooltip', align: 'left', editable: true, edittype: 'textarea', width: '300px', fixed: true, editoptions: { rows: '5', cols: '40' }, editrules: { required: true} },
  20.                         { name: 'x', index: 'x', align: 'left', editable: true, edittype: 'select', width: '60px', fixed: true, editoptions: { value: { 1: 'true', 0: 'false'} }, editrules: { required: true} },
  21.                         { name: 'warningexception', index: 'warningexception', align: 'left', editable: true, edittype: 'select', width: '60px', editoptions: { value: { 1: 'true', 0: 'false'} }, editrules: { required: true} }
  22.                       ],
  23.             //pager for grid
  24.             pager: $('#jqgpFactors'),
  25.             rowNum: 60,
  26.             sortname: 'id',
  27.             sortorder: 'asc',
  28.             viewrecords: true,
  29.             height: '100%',
  30.             width: 900,
  31.             subGrid: true,
  32.             subGridRowExpanded: function (subgrid_id, row_id) {
  33.                 var subgrid_table_id;
  34.                 var subgrid_pager_id;
  35.                 subgrid_table_id = subgrid_id + "_t";
  36.                 subgrid_pager_id = "p_" + subgrid_table_id;
  37.                 $("#" + subgrid_id).html("<table id='" + subgrid_table_id + "' class='scroll'></table><div id='" + subgrid_pager_id + "' class='scroll'></div>");
  38.                 $("#" + subgrid_table_id).jqGrid({
  39.                     url: '@Url.Action("GetFactorDetails")',
  40.                     postData: { QuestionId: function () { return row_id; } },
  41.                     datatype: "json",
  42.                     mtype: "POST",
  43.                     colNames: ['id', 'questionid', 'text', 'influence', 'weight'],
  44.                     colModel: [
  45.                                 { name: "id", index: "id", key: true, hidden: true },
  46.                                 { name: "questionid", index: "questionid", hidden: true },
  47.                                 { name: "text", index: "text", width: 700, editable: true, edittype: 'text' },
  48.                                 { name: "influence", index: "influence", width: 80, editable: true, edittype: 'text', editrules: { required: true, integer: true} },
  49.                                 { name: "weight", index: "weight", sortable: false, width: 80, editable: true, edittype: 'text', editrules: { required: true, integer: true} }
  50.                               ],
  51.                     height: '100%',
  52.                     rowNum: 5,
  53.                     sortname: 'id',
  54.                     sortorder: 'asc',
  55.                     pager: subgrid_pager_id,
  56.                     editurl: 'clientArray',
  57.                     width: 860
  58.                 });
  59.                 $("#" + subgrid_table_id).jqGrid('navGrid', '#' + subgrid_pager_id, { edit: false, add: false, del: false });
  60.                 $("#" + subgrid_table_id).jqGrid('inlineNav', '#' + subgrid_pager_id, {
  61.                     addParams: {
  62.                         addRowParams: {
  63.                             keys: true,
  64.                             url: '@Url.Action("AddFactorDetail")'
  65.                         }
  66.                     },
  67.                     editParams: {
  68.                         url: '@Url.Action("UpdateFactorDetail")'
  69.                     },
  70.                     add: true,
  71.                     edit: true,
  72.                     save: true,
  73.                     cancel: true
  74.                 }
  75.                 });
  76.             }
  77.         });
  78.  
  79.         $.jgrid.nav.addtext = "Add Record";
  80.         $.jgrid.nav.edittext = "Edit Record";
  81.         $.jgrid.nav.deltext = "Delete Record";
  82.         $('#jqgFactors').jqGrid('navGrid', '#jqgpFactors',
  83.             { add: true, del: true, edit: true, search: false },
  84.             { width: 'auto', url: '@Url.Action("UpdateFactor")' },
  85.             { width: 'auto', url: '@Url.Action("UpdateFactor")' },  //insert
  86.             { width: 'auto', url: '@Url.Action("DeleteFactor")' });
  87.         $('#dlgFactor').dialog({ autoOpen: false, bgiframe: true, resizable: false, title: 'Factor' });
  88.         $('a[data-supplier-id]').live('click', function (e) {
  89.             if (e.preventDefault)
  90.                 e.preventDefault();
  91.             else
  92.                 e.returnValue = false;
  93.  
  94.             var dialogPosition = $(this).offset();
  95.             $.post('@Url.Action("Factor")', { FactorId: $(this).attr('data-supplier-id') }, function (data) {
  96.                 $('#dlgFactor').empty();
  97.                 $('#tmplFactor').tmpl(data).appendTo('#dlgFactor');
  98.                 $('#dlgFactor').dialog('option', 'position', [dialogPosition.left, dialogPosition.top]);
  99.                 $('#dlgFactor').dialog('open');
  100.             });
  101.         });
  102.     });
  103.        
  104. [AcceptVerbs(HttpVerbs.Post)]
  105.     public ActionResult UpdateFactorDetail(FactorDetailModel model, int Id)
  106.     {
  107.             model.QuestionId = Id;
  108.             FactorManager fm = new FactorManager();
  109.             return Json(fm.UpdateDetail(model));
  110.     }
  111.  
  112.     [AcceptVerbs(HttpVerbs.Post)]
  113.     public ActionResult AddFactorDetail(FactorDetailModel model, int QuestionId)
  114.     {
  115.             model.QuestionId = QuestionId;
  116.             FactorManager fm = new FactorManager();
  117.             return Json(fm.AddDetail(model));
  118.     }