jtable中使用jquery的动态字段

raj*_*har 1 java pagination jsp jtable

这里的字段是硬编码的,但我想为我的任务动态获取字段,就像我将在这个jsp中有一个列表,其中包含字段名称,例如:list=[id,name,salary,doj] 此列表可能会针对新请求进行更改.我能有一些想法吗?

 fields: {
                    PersonId: {
                        key: true,
                        create: false,
                        edit: false,
                        list: false
                    },
                    Name: {
                        title: 'Author Name',
                        width: '40%'
                    },
                    Age: {
                        title: 'Age',
                        width: '20%'
                    },
                    Watch: {
                        title: 'Watch',
                        width: '20%',
                        display: function (data) {
                        return '';
                    },
                    RecordDate: {
                        title: 'Record date',
                        width: '30%',
                        type: 'date',
                        create: false,
                        edit: false
                    }
                }
            });
Run Code Online (Sandbox Code Playgroud)

hik*_*kan 11

您可以在服务器端动态构建Javascript代码.

对于客户端,您还可以动态创建字段.

var fields = {
    PersonId: { //I assume that this field is standard
        key: true,
        list: false
    }
};

if(someCondition) {
    fields['Name'] = {
        title: 'Author Name',
        width: '40%'
    };
}

//Add other dynamic fields

$('#PersonTableContainer').jtable({
    title: 'Table of people',
    actions: {
        listAction: '/GettingStarted/PersonList',
        createAction: '/GettingStarted/CreatePerson',
        updateAction: '/GettingStarted/UpdatePerson',
        deleteAction: '/GettingStarted/DeletePerson'
    },
    fields: fields
});
Run Code Online (Sandbox Code Playgroud)

在您的情况下,您可以确定地从列表中添加字段.