Open craigcsruk opened 9 years ago
Can we see the complete code for allowing odata property?
I have added the full customisations I made to jquery.dataTables.odata.js here: http://pastebin.com/y0cHGeLQ
The implementation has grown somewhat since my first comment. The javascript now supports expanding as well as filtering on collections using the oData Any functionality.
At the bottom of the paste you can see my page implementation which should give you some idea on how to use it if your already familiar with using jQuery Datatables as well as the odata plugin.
Hope that helps.
Thank you for that, Craig. I am struggling with expand for a day now. Good thing I found your issue here. I will give your implementation a try. Chreers
@craigcsruk Just wondering if you could make a fork with your changes....
Hi @Worthy7 as requested I have made a fork https://github.com/craigcsruk/jQuery.dataTables.oData with my changes. It hopefully includes the following improvements:
NOTE: Theses have only been proving for my use cases so they may or may not work for you use cases... but I am sure the improvement will at least help!
Nice one, yours should become the master!
hy i am new for using filter with oData . i already can filter by oData base on this https://github.com/craigcsruk/jQuery.dataTables.oData. but can i also filter using render value?. for example: my mData is an ID, from the the ID i want to know date of birth with passing the ID to a function. in my case i only can filter by ID. but i wanna make filter by render value.
I had a few issues trying to use $expand values because of oData needing 'User/UserName' and datatables requiring 'User.Username'. After hacking around a bit I managed to get it supported.
Example for replicating the issue: Url: odata/Clients?$expand=User&$select=Id,Name,User/UserName
Javascript: $(document).ready((function () { $('#clientsTable').dataTable({
The above implementation will perform a valid oData request but will cause an datatables warning "DataTables warning: table id=clientsTable - Requested unknown parameter 'User/UserName' for row 0".
Possible Fix To fix the issue for myself I changed aoColumns to allow an oData property and replaced all usages of mData with oData.
"aoColumns": [ { "mData": "Id", "oData": "Id" }, { "mData": "FirstName", "oData": "FirstName" }, { "mData": "User.UserName", "oData": "User/UserName" } ],
The fix worked for most features except the order by logic. Instead I implemented a hacky string replace:
var asOrderBy = []; for (var i = 0; i < oParams.iSortingCols; i++) { var columnName = oParams["mDataProp" + oParams["iSortCol" + i]].replace(".", "/"); asOrderBy.push(columnName + " " + (oParams["sSortDir_" + i] || "")); }