Giter Club home page Giter Club logo

Comments (5)

MatheusCaiser avatar MatheusCaiser commented on May 24, 2024 1

I figure out how to make a date search, I'm using Postgres and the date type is stored like '2017-01-01 00:00:00', so what I made was to parse date to a date string that have the same format, but in JavaScript. Finally my JS function ended up like this:
$("#dataFilter").datepicker({ format : "dd/mm/yyyy", language : "pt-BR", todayHighlight : true }) .on("changeDate", function(e) { table.column(0).search(e.date.toISOString().substr(0, 10)).draw(); });

And Worked 👍

from spring-data-jpa-datatables.

darrachequesne avatar darrachequesne commented on May 24, 2024

To handle a date, you'll have to provide your own specification (since the library cannot know whether a field contains a date or not):

public DataTablesOutput<User> getUsers(@Valid DataTablesInput input) {
  ColumnParameter parameter0 = input.getColumns().get(0);
  LocalDate date = LocalDate.parse(parameter0.getSearch().getValue());
  Specification additionalSpecification = getSpecificationForDate(date);
  parameter0.getSearch().setValue("");
  return userRepository.findAll(input, additionalSpecification);
}

from spring-data-jpa-datatables.

Mike-the-one avatar Mike-the-one commented on May 24, 2024

Sorry to bring the old thread back. I am having a similar problem. Setting the date between returns empty table.

Here is the code

predicateDate = builder.between(root.<Date>get("orderDateTime"), d1, d2);

from spring-data-jpa-datatables.

hendisantika avatar hendisantika commented on May 24, 2024

Hi @darrachequesne , where is ColumnParameter class imported?

@JsonView(DataTablesOutput.View.class)
	@RequestMapping(value = "/data/users", method = RequestMethod.GET)
	public DataTablesOutput<User> getUsers(@Valid DataTablesInput input) {
		for (ColumnParameter parameter : input.getColumns()) {
			if (!parameter.getData().equalsIgnoreCase("likes"))
				continue;
			// create a specification based on the search value
			val additionalSpecification = getLikesSpecification(parameter
					.getSearch().getValue());
			// remove the search value
			parameter.getSearch().setValue("");
			return userRepository.findAll(input, additionalSpecification);
		}
		return userRepository.findAll(input);
	}

Thanks

from spring-data-jpa-datatables.

carlosluisbm avatar carlosluisbm commented on May 24, 2024

Hi @darrachequesne , where is ColumnParameter class imported?

@JsonView(DataTablesOutput.View.class)
	@RequestMapping(value = "/data/users", method = RequestMethod.GET)
	public DataTablesOutput<User> getUsers(@Valid DataTablesInput input) {
		for (ColumnParameter parameter : input.getColumns()) {
			if (!parameter.getData().equalsIgnoreCase("likes"))
				continue;
			// create a specification based on the search value
			val additionalSpecification = getLikesSpecification(parameter
					.getSearch().getValue());
			// remove the search value
			parameter.getSearch().setValue("");
			return userRepository.findAll(input, additionalSpecification);
		}
		return userRepository.findAll(input);
	}

Thanks

I think the class Column works.

Hi @darrachequesne, I have this same problem. A column in BD that is a Date that cant be search by the value of the input.

Im trying to work on the code for the Specification to solve this, but I cant.

Can you or anybody else write or explain the code inside the method getSpecificationForDate(date)?

Thanks.

from spring-data-jpa-datatables.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.