Search code examples
javascriptjqueryjquery-jtable

delete a record (client only) in JTable using javascript


I'm using JTable and JQuery for an html page, adding the records manually in JTable using jtable addRecord option. I want to delete the added record based on user selection locally i.e., on client side only. Hence, I use the below code, the record contains TeamName & TeamDescription.

$.fn.deleteTeamRow = function() {
            var $selectedRows = $('#TeamContainer').jtable('selectedRows');
            $selectedRows.each(function () {
                var record = $(this).data('record');
                var teamname = record.TeamName;
                $('#TeamContainer').jtable('deleteRecord', {
                    key: teamname,
                    clientOnly: true,
                    success: (function() {
                        alert("record deleted");
                    }),
                    error: (function() {
                        alert("record deletion error!");
                    })
                });
            });
        };

Unable to either get the success or error alert.

Kindly, let me know how to delete a record on client side only.


Solution

  • I was able to resolve the issue the 'key' was missed while defining the columns in the Table.

        $('#TeamContainer').jtable({
                selecting: true,
                columnResizable: false,
                selecting: true, //Enable selecting
                multiselect: true, //Allow multiple selecting
                selectingCheckboxes: true,
                actions: {
                },
                fields: {
                    TeamName: {
                        title: 'Team Name',
                        **key: true,**
                        sorting: true
                    },
                    TeamDescription: {
                        title: 'Team Description',
                        create: false
                    }
                }
            });