/// <summary>
        /// 分页控件-Ajax
        /// </summary>
        /// <param name="ctnrId">内容容器Id</param>
        /// <param name="actionName">动作名称</param>
        /// <param name="controllerName">控制器名称</param>
        /// <param name="routeValues">路由参数</param>
        /// <param name="currentPage">当前页</param>
        /// <param name="totalPage">总页数</param>
        /// <param name="pageSize">每页显示记录数</param>
        /// <param name="totalRecord">总记录数</param>
        /// <param name="recordUnit">记录单位</param>
        /// <param name="recordName">记录名称</param>
        /// <param name="ctrlId">分页控件Id</param>
        /// <param name="cssClass">分页控件css类名</param>
        /// <param name="digitalLinkNum">显示的数组链接个数</param>
        /// <param name="showTotalRecord">显示总记录数</param>
        /// <param name="showCurrentPage">显示当前页</param>
        /// <param name="showTotalPage">显示总页数</param>
        /// <param name="showSelect">显示页码下拉框</param>
        /// <param name="showInput">显示页码输入框</param>
        public static MvcHtmlString PagerAjax(this HtmlHelper htmlHelper, string ctnrId, string actionName, string controllerName, RouteValueDictionary routeValues, int currentPage, int TotalPage, int pageSize, int totalRecord, string recordUnit, string recordName, string ctrlId, string cssClass, int digitalLinkNum, bool showTotalRecord, bool showCurrentPage, bool showTotalPage, bool showSelect, bool showInput)
        {
            PagerConfig _config = new PagerConfig {
                CurrentPage = currentPage, PageSize = pageSize, TotalRecord = totalRecord, RecordUnit = recordUnit, RecordName = recordName
            };

            return(PagerAjax(htmlHelper, ctnrId, actionName, controllerName, routeValues, _config, ctrlId, cssClass, digitalLinkNum, showTotalRecord, showCurrentPage, showTotalPage, showSelect, showInput));
        }
        /// <summary>
        /// 分页控件-Ajax
        /// </summary>
        public static MvcHtmlString PagerAjax(this HtmlHelper htmlHelper, string ctnrId, string actionName, string controllerName, object routeValues, int currentPage, int TotalPage, int pageSize, int totalRecord, string recordUnit, string recordName)
        {
            PagerConfig _config = new PagerConfig {
                CurrentPage = currentPage, PageSize = pageSize, TotalRecord = totalRecord, RecordUnit = recordUnit, RecordName = recordName
            };

            return(PagerAjax(htmlHelper, ctnrId, actionName, controllerName, new RouteValueDictionary(routeValues), _config, "nspager", "nspager", 10, true, true, true, false, false));
        }
示例#3
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            // Create your application here
            SetContentView(Resource.Layout.main);
            Log.Info("GCS", "onCreate");

            _seekBar = FindViewById <SeekBar>(Resource.Id.seekBar1);
            _seekBar.SetOnTouchListener(this);


            mRadioGroup = this.FindViewById <RadioGroup>(Resource.Id.orientation_type);// (RadioGroup)findViewById(R.id.orientation_type);
            mRadioGroup.SetOnCheckedChangeListener(this);

            mPageTotal         = (TextView)FindViewById(Resource.Id.page_total);
            mPageCurrent       = (TextView)FindViewById(Resource.Id.page_current);
            t_page_bar_process = FindViewById <TextView>(Resource.Id.page_bar_process);
            mLayoutManager     = new PagerGridLayoutManager(mRows, mColumns, PagerGridLayoutManager
                                                            .HORIZONTAL);


            // 系统带的 RecyclerView,无需自定义
            mRecyclerView = (RecyclerView)FindViewById(Resource.Id.recycler_view);

            // 水平分页布局管理器
            mLayoutManager.SetPageListener(this);    // 设置页面变化监听器
            mRecyclerView.SetLayoutManager(mLayoutManager);

            // 设置滚动辅助工具
            PagerGridSnapHelper pageSnapHelper = new PagerGridSnapHelper();

            pageSnapHelper.AttachToRecyclerView(mRecyclerView);

            // 如果需要查看调试日志可以设置为true,一般情况忽略即可
            PagerConfig.SetShowLog(true);
            List <string> data = new List <string>();

            for (int i = 1; i <= 15; i++)
            {
                data.Add(i + "");
            }
            // 使用原生的 Adapter 即可
            mAdapter = new MainItemAdapter(data);
            RecyclerView.AdapterDataObserver observer = new DataObserverModel(mAdapter);
            mAdapter.RegisterAdapterDataObserver(observer);
            mRecyclerView.SetAdapter(mAdapter);

            Button btn_addone = this.FindViewById <Button>(Resource.Id.AddOneFunc);

            btn_addone.Click += delegate
            {
                mAdapter.items.Add("add");
                mAdapter.NotifyDataSetChanged();
            };
        }
        /// <summary>
        /// 分页控件-Ajax
        /// <param name="ctnrId">内容容器Id</param>
        /// <param name="actionName">动作名称</param>
        /// <param name="controllerName">控制器名称</param>
        /// <param name="routeValues">路由参数</param>
        /// <param name="pageConfig">分页配置</param>
        /// <param name="ctrlId">分页控件Id</param>
        /// <param name="cssClass">分页控件css类名</param>
        /// <param name="digitalLinkNum">显示的数组链接个数</param>
        /// <param name="showTotalRecord">显示总记录数</param>
        /// <param name="showCurrentPage">显示当前页</param>
        /// <param name="showTotalPage">显示总页数</param>
        /// <param name="showSelect">显示页码下拉框</param>
        /// <param name="showInput">显示页码输入框</param>
        public static MvcHtmlString PagerAjax(this HtmlHelper htmlHelper, string ctnrId, string actionName, string controllerName, RouteValueDictionary routeValues, PagerConfig pageConfig, string ctrlId, string cssClass, int digitalLinkNum, bool showTotalRecord, bool showCurrentPage, bool showTotalPage, bool showSelect, bool showInput)
        {
            UrlHelper     _url        = new UrlHelper(htmlHelper.ViewContext.RequestContext);
            StringBuilder _strBuilder = new StringBuilder("<div id='" + ctrlId + "' class='" + cssClass + "'><p>");

            if (showTotalRecord)
            {
                _strBuilder.Append("共" + pageConfig.TotalRecord + pageConfig.RecordUnit + pageConfig.RecordName + " ");
            }
            if (showCurrentPage)
            {
                _strBuilder.Append("每页" + pageConfig.PageSize + pageConfig.RecordUnit + " ");
            }
            if (showTotalPage)
            {
                _strBuilder.Append("第" + pageConfig.CurrentPage + "页/共" + pageConfig.TotalPage + "页</p> ");
            }
            //首页链接
            if (pageConfig.CurrentPage > 1)
            {
                routeValues["page"] = 1;
                _strBuilder.Append("<p><a class='linkbtn' href='" + _url.Action(actionName, controllerName, routeValues) + "'>首页</a>");
            }
            else
            {
                _strBuilder.Append("<span class='btn'>首页</span>");
            }
            //上一页
            if (pageConfig.CurrentPage > 1)
            {
                routeValues["page"] = pageConfig.CurrentPage - 1;
                _strBuilder.Append("<a class='linkbtn' href='" + _url.Action(actionName, controllerName, routeValues) + "'>上一页</a>");
            }
            else
            {
                _strBuilder.Append("<span class='btn'>上一页</span>");
            }
            //数字导航开始
            int _startPage, _endPage;

            //总页数少于要显示的页数,页码全部显示
            if (digitalLinkNum >= pageConfig.TotalPage)
            {
                _startPage = 1; _endPage = pageConfig.TotalPage;
            }
            else//显示指定数量的页码
            {
                int _forward = (int)Math.Ceiling(digitalLinkNum / 2.0);
                if (pageConfig.CurrentPage > _forward)//起始页码大于1
                {
                    _endPage = pageConfig.CurrentPage + digitalLinkNum - _forward;
                    if (_endPage > pageConfig.TotalPage)//结束页码大于总页码结束页码为最后一页
                    {
                        _startPage = pageConfig.TotalPage - digitalLinkNum;
                        _endPage   = pageConfig.TotalPage;
                    }
                    else
                    {
                        _startPage = pageConfig.CurrentPage - _forward;
                    }
                }
                else//起始页码从1开始
                {
                    _startPage = 1;
                    _endPage   = digitalLinkNum;
                }
            }
            //向上…
            if (_startPage > 1)
            {
                routeValues["page"] = _startPage - 1;
                _strBuilder.Append("<a class='linkbatch' href='" + _url.Action(actionName, controllerName, routeValues) + "'>…</a>");
            }
            //数字
            for (int i = _startPage; i <= _endPage; i++)
            {
                if (i != pageConfig.CurrentPage)
                {
                    routeValues["page"] = i;
                    _strBuilder.Append("<a class='linknum' href='" + _url.Action(actionName, controllerName, routeValues) + "'>" + i.ToString() + "</a>");
                }
                else
                {
                    _strBuilder.Append("<span class='currentnum'>" + i.ToString() + "</span>");
                }
            }
            //向下…
            if (_endPage < pageConfig.TotalPage)
            {
                routeValues["page"] = _endPage + 1;
                _strBuilder.Append("<a class='linkbatch' href='" + _url.Action(actionName, controllerName, routeValues) + "'>…</a>");
            }
            ////数字导航结束
            //下一页和尾页
            if (pageConfig.CurrentPage < pageConfig.TotalPage)
            {
                routeValues["page"] = pageConfig.CurrentPage + 1;
                _strBuilder.Append("<a class='linkbtn' href='" + _url.Action(actionName, controllerName, routeValues) + "'>下一页</a>");
                routeValues["page"] = pageConfig.TotalPage;
                _strBuilder.Append("<a class='linkbtn' href='" + _url.Action(actionName, controllerName, routeValues) + "'>尾页</a>");
            }
            else
            {
                _strBuilder.Append("<span class='btn'>下一页</span><span class='btn'>尾页</span>");
            }
            //显示页码下拉框
            if (showSelect)
            {
                routeValues["page"] = "-nspageselecturl-";
                _strBuilder.Append(" 跳转到第<select id='nspagerselect' data-url='" + _url.Action(actionName, controllerName, routeValues) + "'>");
                for (int i = 1; i <= pageConfig.TotalPage; i++)
                {
                    if (i == pageConfig.CurrentPage)
                    {
                        _strBuilder.Append("<option selected='selected' value='" + i + "'>" + i + "</option>");
                    }
                    else
                    {
                        _strBuilder.Append("<option value='" + i + "'>" + i + "</option>");
                    }
                }
                _strBuilder.Append("</select>页");
                _strBuilder.Append("<script type='text/javascript'>$('#" + ctrlId + " #nspagerselect').change(function () {$.post($('#" + ctrlId + " #nspagerselect').attr('data-url').replace('-nspageselecturl-', $('#" + ctrlId + " #nspagerselect').val()), function (data) {$('#" + ctnrId + "').html(data);});});</script>");
            }
            //显示页码输入框
            if (showInput)
            {
                routeValues["page"] = "-nspagenumurl-";
                _strBuilder.Append(" 转到第<input id='nspagernum' type='text' data-url='" + _url.Action(actionName, controllerName, routeValues) + "' />页");
                _strBuilder.Append("<script type='text/javascript'>$('#" + ctrlId + " #nspagernum').keydown(function (event) {if (event.keyCode == 13) { $.post($('#" + ctrlId + " #nspagernum').attr('data-url').replace('-nspagenumurl-', $('#" + ctrlId + " #nspagernum').val()), function (data) {$('#" + ctnrId + "').html(data);}); } });</script>");
            }
            _strBuilder.Append("<script type='text/javascript'>$('#" + ctrlId + " a').click(function () {$.post($(this).attr('href'), function (data) {$('#" + ctnrId + "').html(data);});return false; });</script>");
            _strBuilder.Append("</p></div>");
            return(MvcHtmlString.Create(_strBuilder.ToString()));
        }
        /// <summary>
        /// 分页控件
        /// </summary>
        #endregion

        #region Ajax
        /// <summary>
        /// 分页控件-Ajax
        /// </summary>
        public static MvcHtmlString PagerAjax(this HtmlHelper htmlHelper, string ctnrId, string actionName, string controllerName, object routeValues, PagerConfig pagerConfig)
        {
            return(PagerAjax(htmlHelper, ctnrId, actionName, controllerName, new RouteValueDictionary(routeValues), pagerConfig, "nspager", "nspager", 10, true, true, true, false, false));
        }