-
Notifications
You must be signed in to change notification settings - Fork 142
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
x-editable helper #16
Comments
I like the idea of this one. There are a few fields that make it difficult to automate 100% (it's hard to know what As a first step, I imagine a helper that you could interact with something like this: # Direct use, but might be a lot for just one line
datatable_options = {
'columns': [
("My Field", 'my_field', helpers.make_xeditable(type=..., url=...)),
]
}
# Or if there are common fields, you could use it like a helper-factory
my_xeditable = helpers.make_xeditable(type='select2', url=reverse('update:url:name'))
datatable_options = {
'columns': [
("My Field", 'my_field', my_xeditable),
("Another Field", 'another_field', my_xeditable),
# Can still specify new kwargs by chaining the calls together
("Third Field", 'third_field', my_xeditable(title="Special case")),
]
} In the latter case, the helper is still able to accept new arguments at runtime, which would include the actual instance, current value, pk, etc. The type could be omitted in the default scenario where it can be read from the field type (like the default form field widgets). The Javascript case is a little special for that Thanks for the recommendation! |
Yeah, the select 2 one is a bit special because of the ajax request. Probably some similar issues if you wanted to use other x-editable input types such as typeahead. But then again you can just override using javascript anyway so its a non-issue :) |
I've merged the If you have a free moment to try it out, pull down the latest master copy and give this a shot: from datatableview.views import XEditableDatatableView
from datatableview import helpers
class MyDatatable(XEditableDatatableView):
datatable_options = {
'columns': [
("Driver", 'driver', helpers.make_xeditable(type="select2"),
], If the field has The xeditable ajax update URL automatically generated by the helper, and To make this work on the client side, you can use the following Javascript on your template: <script type="text/javascript">
function confirm_datatable_options(options) {
var options = { /* editable() options can go here */ };
options.fnRowCallback = datatableview.make_xeditable(options);
return options;
}
</script>
Let me know if anything feels wrong! Thanks for opening this as a recommended helper! |
i will have to look into it a bit more because I just uninstalled the release version and installed master but before I had done anything it was throwing the following error
I do have a custom implementation of the get_ajax method for that view though so will have to try master on something a bit more straightforward. |
OK, fixed the above error. I saw that you had made some minor changes to get_ajax (or perhaps I wasnt implementing it correctly before!). I use a custom get_ajax for adding filters to my tables, I can explain that idea a bit more on another idea issue. I will come back when I have played around with xeditable implementation. |
Ah yes—I have notes in the release draft about the method signature changes, but of course that's not published yet. My mistake. Here's the copy-paste of it, for reference:
This setup should work better for cases where people are trying to modify the response object's contents. |
I still couldnt get it to work on a simpler datatable view but its highly likely that its related to my setup in some way (I am using bootstrapped datatables and bootstrapped xeditable if that makes any difference). The field showed up as a link to # but on click I got no response (which is why I think its related to the js im using). Unfortunately I havent really got the time to muck about with it at the moment. I guess if its working for you though then its good to go. |
Heres a link to the bootstrapped datatables btw - https://github.com/Jowin/Datatables-Bootstrap3/ |
I modified my test project to use those assets and things seem to work okay for me still. My guess is you might not have the view inheriting from the modified Thanks for the extra attention, at any rate. If you find anything odd in my implementation in the future, please don't hesitate to point it out. I'm relatively new to the xeditable stuff, which is why I took a while to learn how it works and figure something out. |
You mentioned in #15 ideas for helpers. Well im pretty sure I could come up with a bunch of ideas based on what im already hacking together myself. This one is really helpful though.
I am using x-editable https://github.com/vitalets/x-editable. I have created a really simple but stupid way of returning x-editable compatible fields:
Works great but it means passing in the data yourself:
It also requires then adding in the x-editable js implementation yourself also.
Would be lovely to be able to get this all done via datatable-view to have fully editable tables!!
The text was updated successfully, but these errors were encountered: