Skip to content

Searching works only if all columns are Strings. #10

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

Open
AnasQiblawi opened this issue Sep 17, 2021 · 1 comment
Open

Searching works only if all columns are Strings. #10

AnasQiblawi opened this issue Sep 17, 2021 · 1 comment

Comments

@AnasQiblawi
Copy link

Error occurs when there is any non-string column across the table.
can you improve it so it search even through:

  • Numbers
  • Dates

Mongoose SchemaTypes:
String
Number
Date
Buffer
Boolean
Mixed
ObjectId
Array
Decimal128
Map
Schema


  • Table Columns are
- username      = String
- age           = Number    // Couse of error
- gender        = String

  • Request POST
{
  "draw": "6",
  "columns": [
    {
      "data": "username",
      "name": "",
      "searchable": "true",
      "orderable": "true",
      "search": {
        "value": "",
        "regex": "false"
      }
    },
    {
      "data": "age",
      "name": "",
      "searchable": "true",
      "orderable": "true",
      "search": {
        "value": "",
        "regex": "false"
      }
    },
    {
      "data": "gender",
      "name": "",
      "searchable": "true",
      "orderable": "true",
      "search": {
        "value": "",
        "regex": "false"
      }
    }
  ],
  "order": [
    {
      "column": "0",
      "dir": "asc"
    }
  ],
  "start": "0",
  "length": "10",
  "search": {
    "value": "My Search Value",
    "regex": "false"
  }
}
  • Error response
{
  "error": {
    "stringValue": "\"/My Search Value/i\"",
    "valueType": "RegExp",
    "kind": "Number",
    "value": {},
    "path": "age",
    "reason": {
      "generatedMessage": true,
      "code": "ERR_ASSERTION",
      "actual": false,
      "expected": true,
      "operator": "=="
    },
    "name": "CastError",
    "message": "Cast to Number failed for value \"/My Search Value/i\" (type RegExp) at path \"age\" for model \"User\""
  }
}
  • Alert on browser
DataTables warning: table id=sortTable - Ajax error. 
For more information about this error,
please see http://datatables.net/tn/7
@AnasQiblawi
Copy link
Author

Occasionally, I find myself relying on this repository,
which is why I've taken the initiative to fork it and make several tailored enhancements to better align with my specific project needs.
These modifications not only cater to my requirements but also have the potential to benefit others in similar situations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant