dycodedev/mongo-datatable

Case caseInsensitive Search?

Closed this issue · 8 comments

I tried adding caseInsensitive to both my jquery

$("#data-table").DataTable({
            "pageLength": 100,
            "aoColumnDefs": [
                { "mData": "archived", "name": "archived",  "aTargets": 0},
                { "mData": "offerId", "name": "offerId" ,   "aTargets": 1 },
                { "mData": "cpaNetwork", "name": "cpaNetwork",   "aTargets": 2  },
                { "mData": "voluumOfferName", "name": "voluumOfferName",   "aTargets": 3  },
                { "mData": "carrier", "name": "carrier",   "targets": 4  },
                { "mData": "countryCode", "name": "countryCode",   "aTargets": 5  },
                { "mData": "cpaOfferId", "name": "cpaOfferId",   "aTargets": 6  },
                { "mData": "dateCreated", "name": "dateCreated",   "aTargets": 7  },
                { "mData": "dateUpdated", "name": "dateUpdated",   "aTargets": 8  },
                { "mData": "shortName", "name": "shortName",   "aTargets": 9  },
                { "mData": "offerUrl", "name": "offerUrl",   "aTargets": 10  },
                { "mData": "country", "name": "country",   "aTargets": 11  },
                { "mData": "shortCyrptoName", "name": "shortCyrptoName",   "aTargets": 12  },
                { "mData": "fullCryptoName", "name": "fullCryptoName",   "aTargets": 13  },
                { "mData": "payout", "name": "payout",   "aTargets": 14  },
                ],
            "order": [[8, "desc"]],
            "processing": true,
            "search": {
                "caseInsensitive": true
            },
            serverSide: true,
            ajax: {
                url: '/offers/offerDbSearch',
                type: 'GET'
            },
        });

and also my node script

var options = req.query;
    options.search.caseInsensitive = true

Without caseInsensitive working, my search results are always a bit skewed. Any ideas?

In mongo-datatable module, lib/column.js find a function called parseSearchValue, inside there try changing to return new RegExp(value, 'gi'); instead of return new RegExp(value, 'g');. Here gi stand for global insensitive.

Thanks @Satish-Acharya ! It worked like a charm! Any chance a dev can turn this into a param so we will not need to edit the package files? I feel like insensitive will be important for people other than myself as well.

@dregge8 , its a constant, currently we don't have any away to pass it as parameter without hacking a code, until author changes it.

Hi, sorry for the super duper late response. I'm going to solve this matter, so please kindly wait for the next update.

@alwint3r Thanks! Any idea when this will propagate to npm?

Tonight if possible (my timezone is GMT+7).

I also want to confirm something, is the search.caseInsensitive property sent to the server when you add

search: {
  caseInsensitive: true
}

to jquery datatables configuration ?

I'm using jquery datatables version 1.10.16 and didn't see caseInsensitive property inside search object.

I plan to implement this option by attaching caseInsensitive directly to the options object that is passed to the MongoDataTable constructor.

So, to enable the case insensitive search, you need to set the options.caseInsensitive to true.

Case insensitive search will be a default behavior in the next major release. I'm gonna refactor the whole code since it's pretty old by now.

So, to enable the case insensitive search, you need to set the options.caseInsensitive to true.

This. The search parameter you mentioned from jquery was not being sent, so I was reconfiguring within node.

You can enable case insensitive search by setting caseInsensitiveSearch to true now. It is published to npm.