본문 바로가기

js/jsGrid

[jsgrid] options fields 변경하기



<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title></title>
    <script type="text/javascript">
    var defaultFields = [
        { name: "CLTR_MNMT_NO", type: "checkbox", width: 20, title: "<input type=\"checkbox\" id=\"checkAll\" />" },
        { name: "CLTR_MNMT_NO_TEXT", type: "text", width: 100, title: "<div>물건번호<div class=\"lightBlue\">물건종류(용도)</div>", validate: "required" },
        { name: "CLTR_NM", type: "text", title: "<div class=\"text-center col-sm-12\">소재지</div>", width: "40%" },
        { name: "MIN_BID_PRC_TEXT", type: "text", title: "<div>감정가(원)<div class=\"lightBlue\">최저입찰가(원)</div>", width: 100 },
        { name: "PBCT_CLTR_STAT_NM", type: "text", title: "<div class=\"col-sm-12\">진행상태</div>", width: 80, align: "center" },
        { name: "PBCT_BEGN_DTM", type: "text", title: "<div>입찰시작</div><div class=\"lightBlue\">입찰마감</div>", width: 80, align: "center" },
    ];
    var photoListFields = [
        { name: "CLTR_MNMT_NO", type: "checkbox", width: 20, title: "<input type=\"checkbox\" id=\"checkAll\" />" },
        { name: "IMG_PATH", type: "text", width: 100, title: "<div class=\"text-center\">사진</div>", validate: "required" },
        { name: "CLTR_MNMT_NO_TEXT", type: "text", width: 100, title: "<div>물건번호<div class=\"lightBlue\">물건종류(용도)</div>", validate: "required" },
        { name: "CLTR_NM", type: "text", title: "<div class=\"text-center col-sm-12\">소재지</div>", width: "40%" },
        { name: "MIN_BID_PRC_TEXT", type: "text", title: "<div>감정가(원)<div class=\"lightBlue\">최저입찰가(원)</div>", width: 100 },
        { name: "PBCT_CLTR_STAT_NM", type: "text", title: "<div class=\"col-sm-12\">진행상태</div>", width: 80, align: "center" },
        { name: "PBCT_BEGN_DTM", type: "text", title: "<div>입찰시작</div><div class=\"lightBlue\">입찰마감</div>", width: 80, align: "center" },
        { name: "APSL_ASES_AVG_AMT", type: "number", title: "<div class=\"lightBlue text-center\">감정가</div>", visible: false },
        { name: "MIN_BID_PRC", type: "number", title: "<div class=\"lightBlue text-center\">최저입찰가</div>", visible: false },
        { name: "PBCT_CLS_DTM", type: "text", title: "<div class=\"lightBlue text-center\">입찰마감</div>", visible: false }
    ];

    $("#jsGrid").jsGrid({
        width: "100%",
        height: "auto",
        inserting: false,
        editing: false,
        sorting: false,
        heading: true,
        paging: true,
        pageSize: 20,
        pageButtonCount: 10,
        pagerContainer: "#externalPager",
        //pagerFormat: "&nbsp;&nbsp; total pages: {pageCount} {first} {prev} {pages} {next} {last} ",
        pagerFormat: "{first} {prev} {pages} {next} {last}",
        //pagerFormat: "{pages}",
        pagePrevText: "<",
        pageNextText: ">",
        pageFirstText: "<<",
        pageLastText: ">>",
        pageNavigatorNextText: "&#8230;",
        pageNavigatorPrevText: "&#8230;",
        controller:
        {
            loadData: function (filter) {
                return $.ajax({
                    type: "POST",
                    url: "/Data/BidProc",
                    data: filter,
                    dataType: "JSON"
                })
            }
        },
        fields: defaultFields
    });

    jQuery(document).ready(function ($) {
        $("#btnToggleChangeFields").on("click", function () {
            if (fieldState === "LIST") {
                $("#jsGrid").jsGrid("option", "fields", photoListFields);
                fieldState = "PHOTO";
                $("#btnToggleChangeFields").text("목록");
            } else {
                $("#jsGrid").jsGrid("option", "fields", defaultFields)
                fieldState = "LIST";
                $("#btnToggleChangeFields").text("사진");
            }
            $("#jsGrid").jsGrid("reset");
        });
    });
    </script>

</head>
<body>

</body>
</html>