温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

bootstrap中bootstrap-editable和bootstrap-fileinput怎么用

发布时间:2021-08-09 14:15:11 阅读:139 作者:小新 栏目:web开发
开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

这篇文章主要介绍了bootstrap中bootstrap-editable和bootstrap-fileinput怎么用,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。

数据库中为datetime类型,.net读取数据已Json格式发回给前台页面:例如:使用bootstrap表格插件Ⅹ

 formatter: function (value, row, index) {
            var date = new Date(parseInt(value.slice(6)));
            return date.getFullYear() + '-' + parseInt(date.getMonth() + 1) + '-' + date.getDate() + " " + date.getHours() + ":" + date.getMinutes()+":"+date.getSeconds();
          }

使用bootstrap-editable时需要引用

<script src="~/Scripts/bootstrap3-editable/js/bootstrap-editable.min.js"></script>
<script src="~/Scripts/bootstraptable/dist/extensions/editable/bootstrap-table-editable.min.js"></script>

初始化时:

{
          field: 'SkuPurchasePrice',
          title: '采购价',
          align: 'center',
          editable: {
            type'text',
            title: '采购价',
            validate: function (v) {
              if (v < 0return '采购价不能小于0';
            }
          }
        }, {
          field: 'QtyAvailable',
          title: '库存可用量',
          align: 'center',
          editable: {
            type'text',
            title: '库存可用量',
            validate: function (v) {
              if (v < 0return '库存可用量不能小于0';
            },           
          },          
        }

事件:

onEditableSave: function (field, row, oldValue, $el) {
          $.ajax({
            type'post',
            url: "@Url.Action("EditNumber")",
            dataType: 'JSON',
            data: { "row": JSON.stringify(row) },
            success: function (data) {
              if (data.ResultType == 0) {
                toastr.success(data.Message);
              }
              else {
                toastr.warning(data.Message);
              }
            },
            error: function () {
              toastr.error("出错了,请联系管理员");
            }
          });
        }

bootstrap-fileinput使用:

引用

<script src="~/Scripts/AdminLTE2.3.0/bootstrap/js/fileinput.min.js"></script>

初始化:

 <label class="control-label col-sm-1">商品上传</label>
              <div class="col-sm-2"><input type="file" id="ProductsUpload" name="ProductsUpload" /></div>
              <div class="col-sm-1"><a href="~/ProductsExcel/DownloadTemplate?type=5" rel="external nofollow" target="_blank">下载模板</a></div>
function initFileInput(ctrlName) {
      var control = $('#' + ctrlName);
      control.fileinput({
        language'zh'//语言
        uploadUrl"@Url.Action("ExcelLeadingIn")"//action
        autoReplacetrue,
        maxFileCount1//最大上传数量
        allowedFileExtensions: ["xlsx""xls"],
        browseClass"btn btn-primary"//按钮样式
        dropZoneEnabledfalse,
        enctype'multipart/form-data',
        showRemovetrue//是否显示删除按钮
        showBrowsetrue//显示浏览图片按钮
        msgFilesTooMany"选择上传的文件数量({n}) 超过允许的最大数值{m}!",
        msgInvalidFileExtension:"只支持.xlsx和.xls文件的格式上传",
        fileActionSettings: {
          showUploadfalse//预览图片上传按钮
          showRemovefalse//预览图片remove按钮
          showZoomfalse //关闭预览图片按钮
        }
      }).on('fileuploaded'function (event, data, previewId, index) {//上传图触发事件
        if (data.response.state == 1) {
          $('#excelLendingDiv h6').html($('#excelLendingDiv h6').html() + data.response.result+"<br/>");
        }
        else {
          toastr.error(data.response.result);
        }
      }).on('filecleared'function (event) {//remove触发事件
        control.show();
      });
    }

 后台上传:

 [HttpPost]
    public ActionResult ExcelLeadingIn()
    {     
      var files = Request.Files;
      string name=files.Keys[0].ToString();
      if (files != null && files.Count > 0)
      {       
        var file = files[0];        
        string path = Server.MapPath("~/Content/excel/") + file.FileName;//文件保存在当前域名下的Content/excel/中
        file.SaveAs(path);       
        string mess = OfferServer.ProductsDetail.InsertExcel(path,file.InputStream,name);
        return Json(new { state = 1, result = mess });
      }
      return Json(new { state = 0, result = "上传发生错误,请检查后重试" });
    }

感谢你能够认真阅读完这篇文章,希望小编分享的“bootstrap中bootstrap-editable和bootstrap-fileinput怎么用”这篇文章对大家有帮助,同时也希望大家多多支持亿速云,关注亿速云行业资讯频道,更多相关知识等着你来学习!

亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI

开发者交流群×