zoukankan      html  css  js  c++  java
  • datatables-2

    <table id="gridtable" class="gridtable">//声明jquery datatables
    <thead>
    <tr>
    <th>Name
    </th>
    <th>Value
    </th>
    <th>DisplayOrder
    </th>
    </tr>
    </thead>
    <tbody>
    .....//datatables内容,此处省略
    </tbody>
    </table>
    <input type="button" id="add" value="Add" />//添加按钮
    <input type="button" id="edit" value="Edit" />//编辑按钮
    <input type="button" id="delete" value="Delete" />//删除按钮


    <div id="e_Attributes">//声明dialog,异步更新
    @using (Ajax.BeginForm("Update", "Product", new AjaxOptions
    {
    UpdateTargetId = "d_Attributes",
    OnSuccess = "dialogClose",
    HttpMethod = "Post",
    }))
    {
    <table>
    <tbody>
    <tr>
    <td>Name</td>
    <td>
    <input id="name" name="Name" type="text" style="250px" class="required"/>*</td>
    </tr>
    <tr>
    <td>Value</td>
    <td>
    <input id="value" name="Value" type="text" style="250px" class="required"/>*</td>
    </tr>
    <tr>
    <td>DisplayOrder</td>
    <td>
    <input id="displayOrder" name="DisplayOrder" type="text" style="128px" class="required"/>*</td>
    </tr>
    <tr>
    <td>
    <input id="submit" type="submit" name="submit" value="Submit" />
    <input id="hiddenValue" type="hidden" name="hiddenValue" />
    </td>
    </tr>
    </tbody>
    </table>
    }
    </div>

    <script type="text/javascript">
    function dialogClose() {
    $("#e_Attributes").dialog("close");
    }

    $("#e_Attributes").dialog({
    modal: true,
    autoOpen: false,
    show: {
    effect: "blind",
    duration: 1000
    },
    hide: {
    effect: "explode",
    duration: 1000
    },
    400
    });

    var editor;

    $(function () {
    //声明datatable
    $("#gridtable").dataTable().fnDestroy();
    editor = $('#gridtable').dataTable({
    "bInfo":false,
    "bServerSide": false,
    'bPaginate': false, //是否分页。
    "bProcessing": false, //当datatable获取数据时候是否显示正在处理提示信息。
    'bFilter': false, //是否使用内置的过滤功能。
    'bLengthChange': false, //是否允许用户自定义每页显示条数。
    'sPaginationType': 'full_numbers', //分页样式
    });
    //单击,赋值,改样式
    $("#gridtable tbody tr").click(function (e) {
    if ($(this).hasClass('row_selected')) {
    $(this).removeClass('row_selected');
    putNullValue()
    }
    else {
    editor.$('tr.row_selected').removeClass('row_selected');
    $(this).addClass('row_selected');
    var aData = editor.fnGetData(this);
    if (null != aData) {
    putValue(aData);
    }
    }
    });
    //双击
    $("#gridtable tbody tr").dblclick(function () {
    if ($(this).hasClass('row_selected')) {
    //$(this).removeClass('row_selected');
    }
    else {
    editor.$('tr.row_selected').removeClass('row_selected');
    $(this).addClass('row_selected');
    }

    var aData = editor.fnGetData(this);
    if (null != aData) {
    putValue(aData);
    }

    $("#hiddenValue").val("edit");
    $("#e_Attributes").dialog("open");

    });
    //添加
    $("#add").click(function () {
    editor.$('tr.row_selected').removeClass('row_selected');
    putNullValue();

    $("#hiddenValue").val("add");
    $("#e_Attributes").dialog("open");
    });
    //编辑
    $("#edit").click(function () {
    var productAttributeID = $("#productAttributeID").val();
    if (productAttributeID != "" && productAttributeID != null) {
    $("#hiddenValue").val("edit");
    $("#e_Attributes").dialog("open");
    }

    });
    //删除
    $("#delete").click(function () {
    var productAttributeID = $("#productAttributeID").val();
    var productID = $("#productID").val();
    if (productAttributeID != null && productAttributeID != "") {
    if (confirm("Delete?")) {
    $.ajax({
    type: "GET",
    url: "@Url.Action("DeleteAttribute", "Product")",
    data: { ProductID: productID, ProductAttributeID: productAttributeID },//参数名要和Action 中的参数名相同
    dataType: "html",
    cache: false,
    success: function (result) {
    $("#d_Attributes").html(result);
    $("#productAttributeID").val(null);
    }
    });
    }
    }
    });

    //赋空值,并去除input-validation-error样式(此样式不管有无,均可去除,所以不用判断了)
    function putNullValue() {
    。。。。。。//此处省略
    }
    //赋值
    function putValue(aData) {
    。。。。。。//此处省略
    }
    });

    $.ajaxSetup({ cache: false });
    </script>

  • 相关阅读:
    MongoDB数据库遭大规模勒索攻击,被劫持26000多台服务器 #精选GITHUBMYSQL
    前端追着设计砍系列的9个超酷网页特效
    15款不容错过的前端开发Javascript和css类库
    恶性循环中的永生bug,可以说是相当写实了
    你是码农还是专家?看看你是哪一类程序员
    夏天过去了, 姥爷推荐几套来自smashingmagzine的超棒秋天主题壁纸
    五毛党可能要失业了,因为AI水军来了
    现代软件工程 第五章 【团队和流程】练习与讨论
    现代软件工程 第四章 【结对编程】练习与讨论
    现代软件工程 课件 软件工程师能力自我评价表
  • 原文地址:https://www.cnblogs.com/sunhai2016/p/5982415.html
Copyright © 2011-2022 走看看