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 actions for Edit/Delete/Update #620
Comments
I'm actually looking into the same thing right now. If you find a good solution, please share. I will do the same. One solution is creating two jTables. One with all the needed actions actions: { and one without. You would use your server-side language and create logic which choose which table to display. But, that really is heavy handed way to achieve the desired result. Which server-side language are you working with? PHP? JS? C#? |
Got it! This stack overflow question helped me to understand how I could conditionally execute javascript inside an MVC Razor view. Here is my example code. actions: { listAction: '@Url.Action("ListAudit")', @if (false) { deleteAction: '/Demo/DeleteStudent', } updateAction: '/Demo/UpdateStudent', createAction: '/Demo/CreateStudent' }, Simply replace false with whatever logic you need. For instance, you could check whether a user is in a particular role and only show the delete button if it is true. @if (User.IsInRole("admins")) { deleteAction: '/Demo/DeleteStudent', } |
Thanks for your post, actually i' m working with Asp.net, can yu provide me the above code with bit more detail, because i tried it, its not working proper |
Github is stripping out the text tags <> from my code. You will need those! Check the link I posted for an example using text tags. I'll update this post with a better example tomorrow. |
Thank you ll be waiting for your post |
The magic happens inside the @if (yourcondition) { <text> // your conditional javascript code </text> } Here is a more full example. Once again, this is ASP.NET MVC with Razor views.
|
This doesn't work for me. I have no idea what MVC3 or Razor are. I'm looking at simple javascript with php doing the SQL manipulation on the server side. As for the initial jtable layout, the only thing happening on the page is javascript and some supporting CSS. Using the @if function in any way causes the jtable to not display. Commenting out the offending lines restores it to functionality. Any pointers in accomplishing this in standard javascript/html/php would be great. As you can see below I am manually declaring a variable to conditionally assess but ultimately I will be using a php $_SESSION variable which is largely irrelevant to this example which is why I simplified it so. Code sample: <script type="text/javascript">
var var1 = 1;
$(document).ready(function () {
//Prepare jTable
$('#Projects').jtable({
title: 'Projects',
jqueryuiTheme: true,
paging: true,
pageSize: 10,
sorting: true,
selecting: true,
defaultSorting: 'projectid ASC',
actions: {
listAction: 'projectsactions.php?action=list',
createAction: 'projectsactions.php?action=create',
updateAction: 'projectsactions.php?action=update',
@if (var1 == 1) {
<text>
deleteAction: 'projectsactions.php?action=delete'
</text>
}
},
fields: {
projectid: {
key: true,
sorting: true,
title: 'Project ID',
width: '10%'
}, |
Sorry, my example doesn't work for PHP, it only works for those jTable user's using ASP.NET as their server side language. Please do post when you get a working PHP example, I'm sure that would be useful! Have you tried kjoye's solution for PHP over here? |
Wow, not sure how I missed that as it is referenced both ways and I had already read that thread. Thanks, that works for this purpose. |
My requirement is to show Edit/Delete/Add link on conditional based using conditional actions. Can anybody help me.Please its a urgent requirement.
Thanks in advance.
The text was updated successfully, but these errors were encountered: