⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

insert data manually or searching



tofayelahmed
  • profile picture
  • Member

Posted 17 April 2012 - 13:19 PM

Thanx web-johnyy for grocery crud.
I already make a application by grocery crud.
Now I starting another application. But I faces a problem.
I attach a file.
Here see a input field name of source which is get by set_relation function.
Now I need.
1. If not match the searching data, i want to type new source data and then insert.
2. If match and need to extend some words(if need) and then insert.
3. if match and no need to exatend and then insert.

Help please.

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 17 April 2012 - 23:01 PM

Yes I understand what you mean but there is not any functionality for that in grocery CRUD yet. Also I don't know anyone that has a similar extension/example for this.
You have to change the core library and add this to your project. If you do it, it will be really useful if you share your code here so you can also help other people with a similar problem.

dropcase
  • profile picture
  • Member

Posted 20 June 2012 - 21:20 PM

I would like to see this option as well... One example (loosely related to the project I'm working on now) would be Job Titles.

- If a job title [b]is[/b] in the list, select and use it.
- If a job title [b]is not[/b] in the list, use it and update the database
- If a job title needs to be updated (misspelling or other reason), select it from the list, make the edit(s), and save to update that record in the database.

I think the last part would be the hardest, especially with foreign keys. Maybe there could be an option to either add as a new record, or update existing?

Still getting used to grocery CRUD, but really like it so far... it's made the admin process a ton easier (thanks!). If I'm able to get anything like that working, I'll be more than happy to share. I haven't seen it elsewhere, but then again - I haven't looked for it too much yet.

// dropcase

fdias
  • profile picture
  • Member

Posted 20 June 2012 - 22:04 PM

My suggestion would be to use a callback_add function to change that field into a javascript that would allow you to choose from a list or type in your selection. The problem I see with this approach is that you would not be able to establish relationships as you would be inserting the field's text and not value. Meaning if you have a list of cars then you would have on your database the car name (mercedes, porsche etc) and not it's ID from a car table.

I hope I was clear :)

dropcase
  • profile picture
  • Member

Posted 21 June 2012 - 19:32 PM

Yes, you were clear. I don't mind the extra work for myself, but the other users of the system I'm building would. ;)

Still trying to figure out how to make it easy enough for most users... and still make it manageable from the backend. Good point on the IDs too, I'll have to wrap my head around that before I get much further. In your example, you'd have to add the new value to the second table, then write the new ID back to the first table. Possible, but maybe a lot of callback_before_update (or insert for adds) work.

Back to the IDE...
// dropcase

fdias
  • profile picture
  • Member

Posted 22 June 2012 - 12:38 PM

Actually if you don't mind writting text to the table (i.e. your combo values won't come from DB), then it's easy enough as you won't have to manage the IDs and insertions on different tables.
If you want to keep this as separate tables, then it's best you enforce the values on the combox. If the value is not there, then you allow the user to open the grid that will eventually populate the combo and register beforehand.

tofayelahmed
  • profile picture
  • Member

Posted 04 November 2012 - 08:46 AM

Hi all.
I solved this problem but i don't know is it appropriate?


//My controller function:

function inventory_add()
{
// Add some js and css file for search
$this->grocery_crud->set_css('css_autocomplete/jquery-ui.css');
$this->grocery_crud->set_js('js_autocomplete/jquery-1.8.2.js');
$this->grocery_crud->set_js('js_autocomplete/jquery-ui.js');
$this->grocery_crud->set_js('js/function_search.js');

$this->grocery_crud->set_table('pos_inventory');
$this->grocery_crud->set_subject('Inventory Setup');

$this->grocery_crud->callback_add_field('author',array($this,'add_field_callback_1')); //field which need search
-----------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------
}

function add_field_callback_1()
{
return '<input id="tags" name="author" style="width:505px; height:25px;" />';
}

// function_search.js code

window.onload = function () {

var alldata_test= new Array;
var ajaxRequest; // The variable that makes Ajax possible!
try{
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
}catch (e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
}catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
}catch (e){
// Something went wrong
alert("Your browser broke!");
return false;
}
}
}

var host = getBaseURL();
url_tags = host+"index.php/inventory/tags_ajaxsearch[/color]/";
var queryString='';

ajaxRequest.open("POST",url_tags, true);
ajaxRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
ajaxRequest.send(queryString);

ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
var resp = ajaxRequest.responseText;
alldata_test = resp.split("xxx");
alert(alldata_test);
$( "#tags" ).autocomplete({
source: alldata_test
});
}

}

}

//tags_ajaxsearch function

function tags_ajaxsearch[/color]()
{
$this->db->select('author');
$this->db->from('pos_inventory');
$query = $this->db->get();
$data1 = array();

foreach ($query->result() as $row)
{
$data1[] = $row->author;
}
$author = implode('xxx', $data1);
echo $author;
}


The Output : [attachment=337:search.png]

Any easy idea?