【问题标题】:Column in Jtable doesn't showJtable 中的列不显示
【发布时间】:2013-12-14 13:34:52
【问题描述】:

我用 JTable 创建了一个 Datagrid,这是我的 JavaScript 代码:

<script type="text/javascript">
    $(document).ready(function () {
        $('#PersonTableContainer').jtable({
            title: 'Table of people',
            actions: {
                listAction: '{{ path("person_list") }}',
                createAction: '',
                updateAction: '',
                deleteAction: ''
            },
            fields: {
                PersonId: {
                    key: true,
                    list: false
                },
                Name: {
                    title: 'Name',
                    width: '40%'
                },
                Age: {
                    title: 'Age',
                    width: '20%'
                },
                PaysId: {
                    title: 'Country',
                    width: '30%'
                }
            }
        });
    });
</script>

代码运行良好,显示所有信息。

____________________________
Name      |  Age    | Country
----------------------------
Mohssine  | 22      | France
Saad      | 10      | USA
____________________________

添加此代码后:

options: '{{ path("get_countries") }}',

当用户想要更改或创建新记录时,为用户显示一个组合框,代码如下:

<script type="text/javascript">
    $(document).ready(function () {
        $('#PersonTableContainer').jtable({
            title: 'Table of people',
            actions: {
                listAction: '{{ path("person_list") }}',
                createAction: '',
                updateAction: '',
                deleteAction: ''
            },
            fields: {
                PersonId: {
                    key: true,
                    list: false
                },
                Name: {
                    title: 'Name',
                    width: '40%'
                },
                Age: {
                    title: 'Age',
                    width: '20%'
                },
                PaysId: {
                    title: 'Country',
                    options: '{{ path("get_countries") }}',
                    width: '30%'
                }
            }
        });
    });
</script>

PHP 代码:返回国家列表的函数

public function getCountriesAction()
    {
        $stmt = $this->getDoctrine()->getEntityManager()
            ->getConnection()
            ->prepare('select country as DisplayText,id as value from countries');
        $stmt->execute();
        $countries = $stmt->fetchAll();

        $jTableResult = array();
        $jTableResult['Result'] = "OK";
        $jTableResult['Options'] = $countries;
        $serializer = new Serializer(array(new GetSetMethodNormalizer()), array('json' =>  new JsonEncoder()));
        $content = $serializer->encode($jTableResult, 'json');
        return new Response($content);
    }

当我显示我的数据网格时,所有信息都在那里,除了我在代码中添加的列之外,它显示没有信息。

____________________________
Name      |  Age    | Country
----------------------------
Mohssine  | 22      | 
Saad      | 10      | 
____________________________

请提供解决方案,谢谢。

【问题讨论】:

    标签: javascript symfony datagrid jtable


    【解决方案1】:

    你必须改变你的功能 getCountriesAction

    public function getregionsAction()
        {
            $stmt = $this->getDoctrine()->getEntityManager()
                ->getConnection()
                ->prepare('select country,id from countries');
            $stmt->execute();
            $countries= $stmt->fetchAll();
    
    
    
            foreach ($countries=  as $key => $value) {
    
                $eil = array();
                $eil["DisplayText"] = $countries[$key]['country'];
                $eil["Value"] = $countries[$key]['id'];
                $rows[] = $eil;  
            }
    
            $jTableResult = array();
            $jTableResult['Result'] = "OK";
            $jTableResult['Options'] = $rows;
    
            $serializer = new Serializer(array(new GetSetMethodNormalizer()), array('json' => new JsonEncoder()));
            $content = $serializer->encode($jTableResult, 'json');
            return new Response($content);
        }
    

    请检查:https://gist.github.com/cristic84/5883136

    我希望这个解决方案对你有所帮助。

    【讨论】:

      猜你喜欢
      • 2014-04-21
      • 2014-09-29
      • 1970-01-01
      • 2012-04-03
      • 2020-07-18
      • 1970-01-01
      • 2011-01-20
      • 2012-01-05
      • 1970-01-01
      相关资源
      最近更新 更多