使用正确的json调用填充jsGrid(1.4.1)......获取空表

时间:2016-05-03 19:13:37

标签: javascript datagrid jsgrid

我一直在为jquery尝试不同的CRUD网格,我遇到了这个非常好的。我之前的帖子使用了不同的网格插件,但是没有满足我的需求,所以我尝试了这个。表格显示正确但行空。

我从使用JSON在线验证器验证的服务器获得此响应

[{"id":"1","anio":"2016","mes":"1","quincena":"1"},{"id":"2","anio":"2016","mes":"1","quincena":"2"}]

这是symfony 1.4中用来构建json的脚本:

 public function executeGetNewsletters(sfWebRequest $request){

    $conn = Doctrine_Manager::getInstance()->getCurrentConnection();

    $qry=$conn->execute("Select id,anio,mes,quincena from newsletters");

            $newsletters = $qry;

            $dataNews = array();

                foreach ($newsletters as $news)
                    {

                           $dataNews[] = array(
                                "id" => $news['id'],
                                "anio" => $news['anio'],
                                "mes" => $news['mes'],
                                "quincena" => $news['quincena'],
                            );

                    }


            echo json_encode($dataNews);

              return sfView::NONE;





  }

这是保存网格的js文件:

$(document).ready(function(){   



    $("#newsletters").click(function(){$.ajax({
            type: "GET",
            url: "/newsletter/getNewsletters"
        }).done(function(newsletters) {

        //  newsletters.unshift({ id: "0", name: "" });

            var news=newsletters;

            alert(news);

            $("#jsGrid").jsGrid({
                height: "90%",
                width: "100%",
                datatype: 'json',        
                sorting: true,
                paging: true,
                filtering:true,
                autosearch: true,
                editing:true,
                autoencode: true,
                gridview: true,
                mtype: 'POST',
                colNames:['ID','Año', 'Mes','Quincena','Option'],

                data: news,

                fields: [
                    { name: "id", type: "number", width: 150 },
                    { name: "anio", type: "number", width: 50 },
                    { name: "mes", type: "number", width: 200 },
                    { name: "quincena", type: "text", textField: "Quincena" },
                    { type: "control" }
                ]
            });


        });
    });
});

这是保存网格的html:

   <?php use_javascript("jurisprudencia/newsletter.js")?>

     <link type="text/css" rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jsgrid/1.4.1/jsgrid.min.css" />
     <link type="text/css" rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jsgrid/1.4.1/jsgrid-theme.min.css" />

     <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jsgrid/1.4.1/jsgrid.min.js"></script>


    <body><div class="col-lg-7 col-lg-7-bc">
        <h3 style="font-size:20px"> JURISPRUDENCIA</h3>

        <p>

            </br>

        </p>


           <div class="col-xs-6 col-sm-4 item ico "><a id="newsletters" target="_blank">Newsletters |</a></div>

           <div class="col-xs-6 col-sm-4 item ico "><a  id="fallos" target="_blank">Navegar |</a></div>

           <div class="col-xs-6 col-sm-4 item ico"><a id="cuadernos_mpd" target="_blank">Cuadernos del MPD</a></div>


            <div id="jsGrid"></div>


     <script>

    </script>




    </div>

我在jsgrid文档中找不到可接受的格式。有谁知道哪种格式正确?感谢

0 个答案:

没有答案