public ActionResult GetDataTables2(DataTable dataTable) {
            List<List<string>> table = new List<List<string>>();

            List<int> column1 = new List<int>();
            for (int i = dataTable.iDisplayStart; i < dataTable.iDisplayStart + dataTable.iDisplayLength; i++) {
                column1.Add(i);
            }

            foreach (var sortDir in dataTable.sSortDirs) {
                if (sortDir == DataTableSortDirection.Ascending) {
                    column1.Sort();
                } else {
                    column1.Sort(delegate(int a, int b) {
                        if (a > b) return -1;
                        if (a < b) return 1;
                        return 0;
                    });
                }
            }

            for (int i = 0; i < column1.Count; i++) {
                table.Add(new List<string> { column1[i].ToString(), "ÄÖÜäöü" + i });
            }

            var result = new DataTableResult(dataTable, table.Count, table.Count, table);
            result.ContentEncoding = Encoding.UTF8;
            return result;
        }
Exemplo n.º 2
0
        public ActionResult GetLatestData(DataTable dataTable)
        {
            var list = _weatherService.GetLatestData().ToList();

            var table = new List<List<string>>();

            list.Skip(dataTable.iDisplayStart).Take(dataTable.iDisplayLength).ToList()
                    .ForEach(x => table.Add(new List<string> { "<a  href='/Home/ViewDetail?station=" + x.StationName + "'>"+ x.StationName +"</a>", x.DateTime.ToString("MM/dd/yyyy H:mm:ss"), x.Temperature.ToString("#0.0000") }));

            var result = new DataTableResult(dataTable, list.Count, list.Count, table) {ContentEncoding = Encoding.UTF8};
            return result;
        }
        public ActionResult GetDataTables(DataTable dataTable) {
            List<List<string>> table = new List<List<string>>();

            List<int> column1 = new List<int>();
            for (int i = dataTable.iDisplayStart; i < dataTable.iDisplayStart + dataTable.iDisplayLength; i++) {
                column1.Add(i);
            }

            foreach (var sortDir in dataTable.sSortDirs) {
                if (sortDir == DataTableSortDirection.Ascending) {
                    column1 = column1.OrderBy(x => x).ToList();
                } else {
                    column1 = column1.OrderByDescending(x => x).ToList();                    
                }
            }

            for (int i = 0; i < column1.Count; i++) {
                table.Add(new List<string> { column1[i].ToString(), "Nummer" + i });
            }

            var result = new DataTableResult(dataTable, table.Count, table.Count, table);
            result.ContentEncoding = Encoding.UTF8;
            return result;
        }
        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) {
            if (controllerContext == null) {
                throw new ArgumentNullException("controllerContext");
            }


            if (bindingContext == null) {
                throw new ArgumentNullException("bindingContext");
            }

            DataTable dataTable = new DataTable();

            //see http://datatables.net/usage/server-side
            string sEcho = bindingContext.ValueProvider.GetValue("sEcho").AttemptedValue;
            if (string.IsNullOrEmpty(sEcho)) {
                throw new ArgumentException("sEcho must always be provided");
            }
            dataTable.sEcho = sEcho;

            string iDisplayStartString = bindingContext.ValueProvider.GetValue("iDisplayStart").AttemptedValue;
            dataTable.iDisplayStart = int.Parse(iDisplayStartString);

            string iDisplayLengthString = bindingContext.ValueProvider.GetValue("iDisplayLength").AttemptedValue;
            dataTable.iDisplayLength = int.Parse(iDisplayLengthString);

            string iColumnsString = bindingContext.ValueProvider.GetValue("iColumns").AttemptedValue;
            dataTable.iColumns = int.Parse(iColumnsString);

            ValueProviderResult sSearchResult = bindingContext.ValueProvider.GetValue("sSearch");
            if (sSearchResult != null) {
                dataTable.sSearch = sSearchResult.AttemptedValue;
            }

            ValueProviderResult bEscapeRegexResult = bindingContext.ValueProvider.GetValue("bEscapeRegex");
            if (bEscapeRegexResult != null) {
                string bEscapeRegexString = bEscapeRegexResult.AttemptedValue;
                bool bEscapeRegex;
                if (!string.IsNullOrEmpty(bEscapeRegexString) &&
                     bool.TryParse(bEscapeRegexString, out bEscapeRegex)) {
                    dataTable.bEscapeRegex = bEscapeRegex;
                }
            }

            for (int i = 0; i < dataTable.iColumns; i++) {
                bool bSortables = false;
                ValueProviderResult bSortableResult = bindingContext.ValueProvider.GetValue(string.Format("bSortable_{0}", i));
                if (bSortableResult != null) {
                    string bSortablesString = bSortableResult.AttemptedValue;
                    bool.TryParse(bSortablesString, out bSortables);
                }
                dataTable.bSortables.Add(bSortables);
            }

            for (int i = 0; i < dataTable.iColumns; i++) {
                bool bSearchables = false;
                ValueProviderResult bSearchableResult = bindingContext.ValueProvider.GetValue(string.Format("bSearchable_{0}", i));
                if (bSearchableResult != null) {
                    string bSearchablesString = bSearchableResult.AttemptedValue;
                    bool.TryParse(bSearchablesString, out bSearchables);
                }
                dataTable.bSearchables.Add(bSearchables);
            }

            for (int i = 0; i < dataTable.iColumns; i++) {
                string sSearchsString = string.Empty;
                ValueProviderResult sSearch_Result = bindingContext.ValueProvider.GetValue(string.Format("sSearch_{0}", i));
                if (sSearch_Result != null) {
                    sSearchsString = sSearch_Result.AttemptedValue;
                }
                dataTable.sSearchs.Add(sSearchsString);
            }

            for (int i = 0; i < dataTable.iColumns; i++) {
                bool bEscapeRegexs = false;
                ValueProviderResult bEscapeRegexsResult = bindingContext.ValueProvider.GetValue(string.Format("bEscapeRegex_{0}", i));
                if (bEscapeRegexsResult != null) {
                    string bEscapeRegexsString = bEscapeRegexsResult.AttemptedValue;
                    bool.TryParse(bEscapeRegexsString, out bEscapeRegexs);
                }
                dataTable.bEscapeRegexs.Add(bEscapeRegexs);
            }

            string iSortingColsString = bindingContext.ValueProvider.GetValue("iSortingCols").AttemptedValue;
            dataTable.iSortingCols = int.Parse(iSortingColsString);

            for (int i = 0; i < dataTable.iSortingCols; i++) {
                string iSortColsString = bindingContext.ValueProvider.GetValue(string.Format("iSortCol_{0}", i)).AttemptedValue;
                dataTable.iSortCols.Add(int.Parse(iSortColsString));
            }

            for (int i = 0; i < dataTable.iSortingCols; i++) {
                string sSortDirString = bindingContext.ValueProvider.GetValue(string.Format("sSortDir_{0}", i)).AttemptedValue;
                if (sSortDirString == "asc") {
                    dataTable.sSortDirs.Add(DataTableSortDirection.Ascending);
                } else {
                    dataTable.sSortDirs.Add(DataTableSortDirection.Descending);
                }
            }

            return dataTable;
        }
 public DataTableResult(DataTable dataTable)
     : this(dataTable.sEcho, 0, 0, null) {
 }
 public DataTableResult(DataTable dataTable, int iTotalRecords, int iTotalDisplayRecords, List<List<string>> aaData)
     : this(dataTable.sEcho, iTotalRecords, iTotalDisplayRecords, aaData) {
 }
		public DataTableResult(DataTable dataTable, int iTotalRecords, int iTotalDisplayRecords, IEnumerable<DataTableRow> aaData) : this(dataTable.sEcho, iTotalRecords, iTotalDisplayRecords)
		{
			if (aaData == null) return;
			this.aaData = aaData.Select(datum => datum.ToDictionary()).ToList();
		}
        public ActionResult GetDataTables3(DataTable dataTable) {
            List<DataTableRow> table = new List<DataTableRow>();

            List<int> column1 = new List<int>();
            for (int i = dataTable.iDisplayStart; i < dataTable.iDisplayStart + dataTable.iDisplayLength; i++) {
                column1.Add(i);
            }

            foreach (var sortDir in dataTable.sSortDirs) {
                if (sortDir == DataTableSortDirection.Ascending) {
                    column1 = column1.OrderBy(x => x).ToList();
                } else {
                    column1 = column1.OrderByDescending(x => x).ToList();
                }
            }

            for (int i = 0; i < column1.Count; i++) {
                table.Add(new DataTableRow("rowId" + i.ToString(), "dtrowclass") { column1[i].ToString(), "ÄÖÜäöü" + i });
            }
            
            return new DataTableResultExt(dataTable, table.Count, table.Count, table);
        }
        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) {
            if (controllerContext == null) {
                throw new ArgumentNullException("controllerContext");
            }

            if (bindingContext == null) {
                throw new ArgumentNullException("bindingContext");
            }

            DataTable dataTable = new DataTable();

            //see http://datatables.net/usage/server-side
            string sEcho = bindingContext.ValueProvider.GetValue("sEcho").AttemptedValue;
            if (string.IsNullOrEmpty(sEcho)) {
                throw new ArgumentException("sEcho must always be provided");
            }
            dataTable.sEcho = sEcho;

            string iDisplayStartString = bindingContext.ValueProvider.GetValue("iDisplayStart").AttemptedValue;
            dataTable.iDisplayStart = int.Parse(iDisplayStartString);

            string iDisplayLengthString = bindingContext.ValueProvider.GetValue("iDisplayLength").AttemptedValue;
            dataTable.iDisplayLength = int.Parse(iDisplayLengthString);

            string iColumnsString = bindingContext.ValueProvider.GetValue("iColumns").AttemptedValue;
            dataTable.iColumns = int.Parse(iColumnsString);

            ValueProviderResult sSearchResult = bindingContext.ValueProvider.GetValue("sSearch");
            if (sSearchResult != null) {
                dataTable.sSearch = sSearchResult.AttemptedValue;
            }

            ValueProviderResult bEscapeRegexResult = bindingContext.ValueProvider.GetValue("bEscapeRegex");
            if (bEscapeRegexResult != null) {
                string bEscapeRegexString = bEscapeRegexResult.AttemptedValue;
                bool bEscapeRegex;
                if (!string.IsNullOrEmpty(bEscapeRegexString) &&
                     bool.TryParse(bEscapeRegexString, out bEscapeRegex)) {
                    dataTable.bEscapeRegex = bEscapeRegex;
                }
            }

            for (int i = 0; i < dataTable.iColumns; i++) {
                bool bSortables = false;
                ValueProviderResult bSortableResult = bindingContext.ValueProvider.GetValue(string.Format("bSortable_{0}", i));
                if (bSortableResult != null) {
                    string bSortablesString = bSortableResult.AttemptedValue;
                    bool.TryParse(bSortablesString, out bSortables);
                }
                dataTable.bSortables.Add(bSortables);
            }

            for (int i = 0; i < dataTable.iColumns; i++) {
                bool bSearchables = false;
                ValueProviderResult bSearchableResult = bindingContext.ValueProvider.GetValue(string.Format("bSearchable_{0}", i));
                if (bSearchableResult != null) {
                    string bSearchablesString = bSearchableResult.AttemptedValue;
                    bool.TryParse(bSearchablesString, out bSearchables);
                }
                dataTable.bSearchables.Add(bSearchables);
            }

            for (int i = 0; i < dataTable.iColumns; i++) {
                string sSearchsString = string.Empty;
                ValueProviderResult sSearch_Result = bindingContext.ValueProvider.GetValue(string.Format("sSearch_{0}", i));
                if (sSearch_Result != null) {
                    sSearchsString = sSearch_Result.AttemptedValue;
                }
                dataTable.sSearchs.Add(sSearchsString);
            }

            for (int i = 0; i < dataTable.iColumns; i++) {
                bool bEscapeRegexs = false;
                ValueProviderResult bEscapeRegexsResult = bindingContext.ValueProvider.GetValue(string.Format("bEscapeRegex_{0}", i));
                if (bEscapeRegexsResult != null) {
                    string bEscapeRegexsString = bEscapeRegexsResult.AttemptedValue;
                    bool.TryParse(bEscapeRegexsString, out bEscapeRegexs);
                }
                dataTable.bEscapeRegexs.Add(bEscapeRegexs);
            }

            string iSortingColsString = bindingContext.ValueProvider.GetValue("iSortingCols").AttemptedValue;
            dataTable.iSortingCols = int.Parse(iSortingColsString);

            for (int i = 0; i < dataTable.iSortingCols; i++) {
                string iSortColsString = bindingContext.ValueProvider.GetValue(string.Format("iSortCol_{0}", i)).AttemptedValue;
                dataTable.iSortCols.Add(int.Parse(iSortColsString));
            }

            for (int i = 0; i < dataTable.iSortingCols; i++) {
                string sSortDirString = bindingContext.ValueProvider.GetValue(string.Format("sSortDir_{0}", i)).AttemptedValue;
                if (sSortDirString == "asc") {
                    dataTable.sSortDirs.Add(DataTableSortDirection.Ascending);
                } else {
                    dataTable.sSortDirs.Add(DataTableSortDirection.Descending);
                }
            }

			// get all the other not well known parameters - these can be defined by the programmer
			// http://datatables.net/release-datatables/examples/server_side/custom_vars.html
			foreach (var key in controllerContext.HttpContext.Request.Form.AllKeys)
			{
				var shortKey = key;
				var underscorePos = shortKey.IndexOf('_');
				if (underscorePos > 0) // -1 is for existance but starting with an _ is also not a shortened key
				{
					shortKey = shortKey.Substring(0, underscorePos + 1);
				}
				if (KnownFormParameters.ContainsKey(shortKey))
				{
					continue;
				}
				dataTable.aoData.Add(key, controllerContext.HttpContext.Request.Form[key]);
			}


            return dataTable;
        }