Question

I want to add a static column with somelink,button for each row in my jTable CRUD Jquery. I`m using the code they are giving for example from jTable site

Here is the code:

<script type="text/javascript">

    $(document).ready(function () {

        //Prepare jTable
        $('#PeopleTableContainer').jtable({
            title: 'Table of people',
            paging: true,
            pageSize: 5,
            sorting: true,
            defaultSorting: 'Name ASC',
            actions: {
                listAction: 'PersonActionsPagedSorted.php?action=list',
                createAction: 'PersonActionsPagedSorted.php?action=create',
                updateAction: 'PersonActionsPagedSorted.php?action=update',
                deleteAction: 'PersonActionsPagedSorted.php?action=delete'
            },
            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
                }
            }
        });

        //Load person list from server
        $('#PeopleTableContainer').jtable('load');

    });

</script>

Focus on Watch field in the display: i want to generate for each row some a href with the id of each row. how i can pull out the id of each row?

Était-ce utile?

La solution

It's pretty easy. See display (http://jtable.org/ApiReference#fopt-display) option. You can define such a field:

TestColumn: {
    title: 'Test',
    display: function (data) {
        var $link = $('<a href="...">a link</a>');
        $link.click(function(){ /* do something on click */ });
        return $link;
    }
}

Autres conseils

Link: {
    title: 'More Info',
    display: function (data) {
        return '<a href="@Url.Action("Index", "Demo")">More Info</a>';
    }
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top