New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conditional Edit/Delete icons per row #113
Comments
I may have misunderstood your question, but i think that your idea depends on data too much so i doubt that there is a chance to make it work in every situation. |
shadov155, I've modified JTable code to make this work already. Just posted this here to include this comment as a Feature in future JTable versions (hopefully). The idea was to hide edit/delete button on a row if certain conditions for the data on that row are met. For example, I have a system user table. System admins should be able to edit any user, but lower access level users may only edit users of lower access level than themselves. |
That's very good idea. We can allow user to define a function that receives the record (and other needed data) as parameter and returns true/false. Thanks for your advice :) |
Can you share your changes to see what you've done for that? |
I have just added a new global option to JTable conditionalActions: {
updateAction: function( record ){
return record.type != 4;
}
} Then changed the code in function _addCellsToRowUsingRecord: function ($row) {
var self = this;
base._addCellsToRowUsingRecord.apply(this, arguments);
if (self.options.actions.updateAction != undefined) {
var $cell = $('<td></td>')
.addClass('jtable-command-column')
.appendTo($row);
if( ( self.options.conditionalActions == undefined || self.options.conditionalActions.updateAction == undefined || self.options.conditionalActions.updateAction( $row.data('record') ) )){
var $span = $('<span></span>').html(self.options.messages.editRecord);
var $button = $('<button title="' + self.options.messages.editRecord + '"></button>')
.addClass('jtable-command-button jtable-edit-command-button')
.append($span)
.appendTo($cell)
.click(function (e) {
e.preventDefault();
e.stopPropagation();
self._showEditForm($row);
});
}
}
}, For delete button is similar. Perhaps you should change the name for options for a better/more suitable name. Hope it helps. |
Hi, Thanks a lot for your solution, I checked it and good one. But I may prefer another approach for that. Now, updateAction is like that: $('#MyTableContainer').jtable({ //... actions: { updateAction: '/Demo/UpdatePerson' //... }, fields: { //Field definitions comes here } }); It can get only a URL string. I can add an option to get an object like that: $('#MyTableContainer').jtable({ //... actions: { updateAction: { url: '/Demo/UpdatePerson', enabled: function(data) { return data.record.type != 4; }, //other options such as success, error callbacks, HTTP method (POST|GET...) can be added later. } //... }, fields: { //Field definitions comes here } }); This can be a more general solution without adding new conditionalActions part in the configuration. Also url can be a function to allow user change url and it's parameters according to record. I'll think on that to find a more general solution. |
That's a better approach, but I tried to maintain compatibility with previous version of JTable, so users don't need to change their code every time a new JTable version comes out. I think you should do this for the option field mentioned in #73 also, as in may not always need to be a function of the data and can be a fixed option object, array or an URL. |
Yes, backward compability is the most important thing for a library and I consider it always. In the #73, function is added a new way of defining options. You can still set url or object like before. Also, updateAction can be string or object anymore. That's acceptable according to the nature of javascript programming. |
That's ok hikalkan :) I'm glad I can contribute to this great project. About #73, i was just making sure you are using typeof checking in your code, because you haven't published the latest version yet. Looking forward to see the new release soon !! Cheers! |
Hi, I am needing the same functionality as well. I want to be able to show/hide (or enable/disable) the Edit and Delete icons based on some condition (record data or member role), The suggestion of making the updateAction to include a "Enabled" option which accepts a function would work perfectly. When do you expect this feature to be available? |
See #893 for a good workaround. |
I have a code like this.
the last field "readyForMaintenance' is a boolean value. need to display different icons for True / False. |
Hi sir how to display success message on adding record in jtable like if we click save button it displays successfully added record. |
Many thanks from VN. @gbisheimer, you are real life saver :) |
It would be nice to have conditional show of edit and delete option icons per row based on row data.
The text was updated successfully, but these errors were encountered: