Пример #1
0
 /// <summary>
 /// grid数据设置
 /// </summary>
 /// <returns></returns>
 public static GridDataAdapterSource GetDataAdapterSource()
 {
     var adp = new GridDataAdapterSource();
     adp.url = "/griddemo/default/GetListSource";//数据源地址
     return adp;
 }
Пример #2
0
        public ActionResult Index()
        {
            var adp = new GridDataAdapterSource();
            adp.url = "/Grid/Data";
            adp.extendData = "a";
            var gc = new GridConfig();
            gc.gridbuttons = new List<GridButton>()
            {
               new GridButton(){ click="add", name="addbutton", icon="jqx-icon-plus", title="添加"},
               new GridButton(){ click="edit", name="editbutton", icon="jqx-icon-edit", title="编辑"},
               new GridButton(){ click="del", name="delbutton", icon="jqx-icon-delete", title="删除"}
            };
            gc.initRowDetails = "initRowDetails";
            gc.pageSize = 20;
            gc.width = "80%";
            gc.filterMode = FilterModel.advanced;
            gc.selectionMode = SelectionMode.multipleRows;
               // gc.rowDetails = true;
            gc.columns = new List<GridColumn>(){
               new GridColumn(){ text="编号", datafield="id",hidden=true, width="40px", cellsalign=AlignType.left,datatype=Datatype.dataint  },
               new GridColumn(){ text="名称", datafield="name", className="minwidth", width="200",  cellsalign=AlignType.left,datatype=Datatype.datastring, cellsRenderer="namefun" },
               new GridColumn(){ text="产品名", datafield="productname", width="500px", cellsalign=AlignType.left,datatype=Datatype.datastring },
               new GridColumn(){ text="数量", datafield="quantity", cellsalign=AlignType.right , datatype=Datatype.dataint },
               new GridColumn(){ text="创建时间", datafield="date", cellsformat="yyyy-MM-dd",cellsalign=AlignType.right, datatype=Datatype.datadate
              }
            };

            JQXGrid.PublicMehtod.ColumnsPrependCheckbox(gc.columns);
            var grid = JQXGrid.BindGrid("#netgrid", adp, gc);
            ViewBag.validationBind = ValidationSugar.GetBindScript("validate_key_grid_index");
            return View(grid);
        }
Пример #3
0
        public static object BindGrid(string gridSelector, GridDataAdapterSource gda, GridConfig gc)
        {
            var rootUrl = GetRootURI();

            if (rootUrl != "/")
            {
                gda.url = rootUrl + "/" + gda.url.TrimStart('/');
            }
            if (gda.datafields == null || gda.datafields.Count == 0)
            {
                foreach (var it in gc.columns)
                {
                    gda.datafields.Add(new GridDatafield()
                    {
                        type = it.datatype, name = it.datafield
                    });
                }
            }

            StringBuilder gridHtml = new StringBuilder();

            gridHtml.AppendFormat(@"var source =
{0}", jss.Serialize(gda));
            gridHtml.AppendLine();
            gridHtml.Append(@" var dataAdapter = new $.jqx.dataAdapter(source, {
                downloadComplete: function (data) {
                    source.totalrecords = data.TotalRows;
                },
                formatData:" + (!string.IsNullOrEmpty(gda.extendData) ? "function (data) {  " + gda.extendData + "(data);  return data; }" : "function (data) { return data; }") + @"
            });");
            gridHtml.AppendLine();
            gridHtml.AppendFormat(@"$(""{0}"").jqxDataTable(", gridSelector);
            if (string.IsNullOrEmpty(gc.renderToolbar))
            {
                gc.renderToolbar = "${toolbar}";
            }

            gridHtml.Append(jss.Serialize(gc));
            gridHtml.Append(");");
            var reval = gridHtml.ToString();

            if (gc.editable)
            {
                reval = reval.Replace("${updateRow}", @" function (rowId, rowData, commit) {commit(true); }");
            }
            else
            {
                reval = reval.Replace("${updateRow}", @" function (rowId, rowData, commit) {   }");
            }
            reval = reval
                    .Replace("\"${toolbar}\"", GetToolbar(gridSelector, gc))
                    .Replace("\"source\":\"dataAdapter\"", "\"source\":dataAdapter")
                    .Replace("\"${localization}\"", "jqxLocalization");
            reval += GetCheckFunc(gridSelector);
            string checkBoxEeventHtml = @"
  $(""" + gridSelector + @""").on(""click"", ""input:checkbox"", function () {
                var th = $(this);
                var isChecked = th.prop(""checked"");
                if (!isChecked) {
                    $(""" + gridSelector + @""").find(""#jqx_datatable_checkbox_all"").jqxCheckBox(""uncheck"");
                }
            });
  setTimeout(function () {
         $(window).resize();
   },2000)
";

            reval = string.Format(@"$(function(){{  {0};
{1} }})", reval, checkBoxEeventHtml);
            reval = ("<script>\r\n") + reval

                    + @"
$(function () {
            var data = $(""body"").on(""click"", """ + gridSelector + @" .jqx_datatable_checkbox"", function () {
                if ($(""body"").data(""checkboxloading"") == null) {
                    var th = $(this);
                    var index = th.attr(""data-cbindex"");
                   console.log(index)
                    var num = 0;
                   var setInt = setInterval(function () {
                        $(""" + gridSelector + @" .jqx_datatable_checkbox"").eq(index).prop(""checked"", true);
                      
                       num = num + 100;
                       if (num / 100 == 15) {
                           clearInterval(setInt);
                        }
                    }, 100);
                }
            });
            setTimeout(function () {
                $(""body"").data(""checkboxloading"", true);
            }, 2000);
       })"
                    + ("\n\r</script>");

            reval = FuncAction(reval, @"""cellsRenderer""\:""(.*?)""");
            reval = FuncAction(reval, @"""renderer""\:""(.*?)""");
            reval = FuncAction(reval, @"""rendered""\:""(.*?)""");
            reval = FuncAction(reval, @"""initRowDetails""\:""(.*?)""");
            reval = FuncAction(reval, @"""createEditor""\:""(.*?)""");
            reval = FuncAction(reval, @"""initEditor""\:""(.*?)""");
            reval = FuncAction(reval, @"""getEditorValue""\:""(.*?)""");
            reval = FuncAction(reval, @"""ready""\:""(.*?)""");
            reval = FuncAction(reval, @"""updateRow""\:""(.*?)""");
            return(reval);
        }
Пример #4
0
        public ActionResult Index()
        {
            var adp = new GridDataAdapterSource();
            adp.url = "/Grid/Data";
            var gc = new GridConfig();
            gc.gridbuttons = new List<GridButton>()
            {
               new GridButton(){ click="add", name="addbutton", icon="jqx-icon-plus", title="添加"},
               new GridButton(){ click="edit", name="editbutton", icon="jqx-icon-edit", title="编辑"},
               new GridButton(){ click="del", name="delbutton", icon="jqx-icon-delete", title="删除"}
            };
            gc.pageSize = 20;
            gc.width = "80%";
            gc.columns = new List<GridColumn>(){
               new GridColumn(){ text="编号", datafield="id", width="40px", cellsalign=AlignType.left,datatype=Datatype.dataint  },
               new GridColumn(){ text="名称", datafield="name", cellsalign=AlignType.left,datatype=Datatype.datastring },
               new GridColumn(){ text="产品名", datafield="productname", cellsalign=AlignType.left,datatype=Datatype.datastring },
               new GridColumn(){ text="数量", datafield="quantity", cellsalign=AlignType.right , datatype=Datatype.dataint },
               new GridColumn(){ text="创建时间", datafield="date", cellsformat="yyyy-MM-dd",cellsalign=AlignType.right, datatype=Datatype.datadate
              }
            };

            var grid = JQXGrid.BindGrid("#netgrid", adp, gc);
            ViewBag.validationBind = ValidationSugar.GetBindScript("validate_key_grid_index");
            return View(grid);
        }
Пример #5
0
 /// <summary>
 /// grid数据设置
 /// </summary>
 /// <returns></returns>
 public static GridDataAdapterSource GetDataAdapterSource()
 {
     var adp = new GridDataAdapterSource();
     adp.url = "/griddemo/ColumnsHierarchies/GetListSource";//数据源地址
     return adp;
 }