vpllan / jQuery.dataTables.oData

jQuery dataTables OData connector
http://vpllan.github.io/jQuery.dataTables.oData/
31 stars 20 forks source link

ASP.net WebAPI errors if $filter is empty and added the ability to extend the ajax settings #4

Closed AlexKeySmith closed 10 years ago

AlexKeySmith commented 10 years ago

If $filter is passed to 'ASP.net WebApi oData' and it is blank, then WebAPI errors. This effects WebApi 1 (and probably v2+ as well).

This change checks if there are any filters first.

AlexKeySmith commented 10 years ago

I've also found I've needed to override the ajax request to e.g. pass in custom headers.

Figured it might come in useful for other people as well.

Great project, keep up the good work :-)

Here is an example of how to use the ajax override:

"fnServerData": function (sUrl, aoData, fnCallback, oSettings) {

                    var ajaxExtendedSettings = {
                        "headers": { "customHeader": "XYZ" }
                    };

                    fnServerOData(sUrl, aoData, fnCallback, oSettings, ajaxExtendedSettings);
                }, // required
JocaPC commented 10 years ago

Hi,

Thanks for this, I will accept the fix for $filter - it is a bug; however, I don't like this approach with new parameter. I don't know would Alan introduce his own 4th parameter in some new version of dataTables and fnServerData function, which will be in conflict with this additional parameter, since there might be others who will just just set fnServerOData to fnServerData. Instead, I would like to set dataTables ajax parameter (see https://next.datatables.net/reference/option/ajax) if we need to change ajax request. In that case, initialization would be something like:

$("#idOfTable").datatables({ "fnServerData": fnServerOData, "ajax": { "headers": { "customHeader": "XYZ" } } })

We could use this ajax object inside the body of plugin using oInit.ajax property and merge it with:

$.extend(ajaxSettings, oInit.ajax); Instead of the current: $.extend(ajaxSettings, ajaxSettingOverrides);

Could you please try would this work for you, and I will apply the version with ajax property instead of the parameter.

Thanks, Jovan

JocaPC commented 10 years ago

Unfortunately, I could not merge your change. First issue (with $filter parameter) is commited as separate change. However, instead of the fourth parameter I have used DataTables ajax option. I believe that this will work for your case, so could you try to take the latest version and try it. If it does not work for you report separate issue and it will be resolved.

AlexKeySmith commented 10 years ago

Hi @JocaPC

I couldn't seem to do a pull request for the commit as 2 separate pulls. But if you've fixed the bug as you're own commit that's ok, I'm happy to help.

oSettings.oInit.ajax seems like a good idea, I've not had a chance to play with it yet, but it seems like a better approach.