TransWikia.com

Xcrud button to search for predefined word and predefined column

Stack Overflow Asked on November 24, 2020

I am using Xcrud Version 1.7
https://www.xcrud.net/

And would like use a button to search/filter for a predefined keyword and column. In the Xcrud Documentation I found buttons with tasks like edit and modal but nothing with search.

the idea is something like this

<button onclick="Xcrud.request('.xcrud-ajax',Xcrud.list_data('.xcrud-ajax',{task:'search',field:keyword}))">Filter Keyword</button>

The documentation has some button functions but I cant get something work with search.
https://www.xcrud.net/demos/index.php?page=js_tricks&theme=default

I need somehow a solution to filter the table data without reloading the entire page and their for use the js function from xcrud instead of loading the entire page again. Maybe somebody worked with xcrud already and has an idea.

thank you in advance

One Answer

I solved it myself with my own little function. It might not be the slickest solution but it works well and like this you can have direct any buttons or menu entries with automatic search in specific columns or all column for phrases.

You then connect your button/link with a simple onclick or like this: search_xcrud('phrase','colname');

Here the function:

function search_xcrud(phrase, col=''){

  console.log('Xcrud Search Started: ' + phrase+ ' Col: ' + col);
  $('input[name ="phrase"]').val(phrase);
  $('select[name ="column"]').val(col);
  $( '.search-go' ).trigger( "click" );

}

You can use the function without "col" and than the function searches in all columns. If you search for a specific column you need to enter the name of the table with the exact label as used in $xcrud->columns!

Example: If you use for example table "clients" with the columns id,name,age.

$xcrud->table('Clients');
$xcrud->columns('id, name, age');

You would call the function like this:

search_xcrud('myphrase','Clients.name'); // incl. tablename and colname! 

If you have doubts about the right column check your source code and look for the select box with the name "column" for all your options in this situation. This depends on the use of relations etc. and might change in this cases.

I hope this helps others since I was looking since quite some time for a easy solution without somehow touching the original Xcrud code. PS: Xcrud is fantastic!

if you have any questions let me know.

Answered by Oliver on November 24, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP