⚠ In case you've missed it we are migrating 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 forum is read-only and soon will be archived. ⚠


Amit Shah

Member Since 23 Oct 2012
Offline Last Active Oct 01 2019 03:30 PM
****-

#16075 autofill

Posted Amit Shah on 23 February 2018 - 05:10 AM

Steps to achieve the same:

 

1. Have to write a script in a JS file which will handle the on change event for the drop down (the source element)

2. In script - make Ajax call to retrieve the price based on the value of selected element.

3. Write a action in controller to retrieve and send back the price / output to the request

4. In the success function for the ajax call - set the value of the field with the element retrieved from the ajax request.

 

1 more important info - add the js in action using set_js function ...

and in the js - call for window.onload function and not $.ready - the $.ready will fail...

 

That's the way u do it..

 

Happy GCing :)




#16046 Change Table and Forms (please reply)

Posted Amit Shah on 16 February 2018 - 04:42 AM

It is quite possible - it is all after all CSS that u need to play around with. There are a few core - bootstrap CSS and then there are the themes css .. u can either add your own css and add the same in the action where you want to serve the same.

 

You can experiment by creating a new CSS and adding it by set_css function - see if it overrides the core css or not. If it dosent - then u just need to hack it into the core CSS whereever applicatible

 

Happy GCing :)




#15825 positionnement footer/header and parameters

Posted Amit Shah on 01 December 2017 - 06:20 PM

Well, my friend, it is pure customization and this is open source. You have full liberty to change the program the way you want to. You can alter the changes in the theme to hide a certain stuff or change the position of certain stuff - no worries. As for showing all the records all the time - there is a simple configuration change - u just need to switch the flag off in the themes config file for pagination.

 

Happy GCing :)




#15823 CodeIgniter and Grocery CRUD

Posted Amit Shah on 01 December 2017 - 12:02 PM

Well my friend - u may consider GC as a plugin. But i will rather call it a library.

Yes, you can use it throughout the codeigniter as and where required.

 

Sorry - there aint much tutorials / any book available. But it is worth going through forum for questions asked / answers shared .. that will increase your knowledge using the same in much better way.

 

If you are a programmer, you will surely love it because this is very flexible with lot of possibilities with the same.

 

Happy GCing :)




#15814 Multiple Callback_before_insert

Posted Amit Shah on 25 November 2017 - 03:41 PM

Well multiple callback is not what the system is currently designed with. For what you can do is you can have 1 single callback.. and in that function you can make a call to the other function before excecuting the actiual callback.

 

Happy GCing :)




#15772 Showing changes when updating field

Posted Amit Shah on 20 November 2017 - 07:08 AM

Hi there,

 

This is a special requirement and not something like a generic requirement. Yes, this is quite possible. You can refer to the following url for the idea as how to achieve the same. 

 

http://www.amitsgara...-add-edit-page/

 

You will have to take in some prominent steps like pushing in the actual values that you have with u currently to a controller / method, there - it will pull in the fresh set of values and compare with the current values (that you have) .. based on the same you can build a json indicating changes. When returned back, you can take in necessary actions / steps as required.

 

Remember 1 thing - the above solution shared looks at handling event based on changes for specific field. But in your case - the same can be switched to some timeout function that will keep making ajax calls. 

 

Hope this clears your query / criteria.

 

Happy GCing :)




#15771 Adding constant to a field

Posted Amit Shah on 20 November 2017 - 06:30 AM

You can follow the solution for the same on the given link

 

http://www.amitsgara...-add-edit-page/




#15766 Export Error Bootstrap theme

Posted Amit Shah on 18 November 2017 - 11:27 AM

Well my friend - u need to enable an extension - mbstring ... 1ce done - u should be able to get through with it easily

 

Happy GCing :)




#15751 It´s possible show a specific record id in grocery crud list

Posted Amit Shah on 16 November 2017 - 11:26 PM

Well u can simply filter the same with the $crud->where clause.. just set your criteria like $db->where .. and all done.

 

Happy GCing:)




#15733 grocery crud master-detail 1_n relation implementation

Posted Amit Shah on 10 November 2017 - 06:33 AM



hello guys I'm a new member and I'd like to share with you my idea which discussed in this topic : 

http://www.grocerycr...er-detail-form/

 

this was a very long time ago and I have no idea if you guys already fix this or not but what I've done is I fix this issue and I would like to share my code with you . 

 

so just to remind you guys this discussion is about implementing master-detail 1_n relation inside tables, for example: 

 

if you have a customers table and each customer has multiple phone numbers

in this case you might want to add the phone number inside the add customer form like this : 

 

2kjGipJ.png

as you can see we can add and remove rows easily by pressing the buttons shown in the figure above ! 

 

so please follow my instructions : 

first create phone_numbers table in your database : 

CREATE TABLE `phone_numbers` (
  `id` int(11) NOT NULL,
  `customer_id` int(11) NOT NULL,
  `phone_type` varchar(255) NOT NULL,
  `phone_number` varchar(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

then inside the customers controller define a new field and call it for example : phone_number like this :

$crud->fields('first_name', 'last_name', 'email', 'gender', 'birth_date', 'phone_number');

note : phone_number field isn't exist inside customers table in the database !!. 

 

after this we add callback for our new field like this :

$crud->callback_add_field('phone', array($this, 'phone_number'));

and then we define our new callback inside our class like this :

    function phone_number($value = '', $primary_key = null){

        $this->db->where('customer_id', $primary_key);
        $numbers = $this->db->get('phone_numbers')->result_array();
        $numbers[1] = array();
        $html = '
            <table id="phone_number"> 
            <tr> <th>type</th><th>Phone number</th> </tr>';
        foreach ($numbers as $number){
            if (!empty($number["phone_number"]) )
            $html.= '<tr><td><input name="phone_types[]" type="text" value="'.$number["phone_type"].'" ></td><td><input name="phone_numbers[]" type="text" value="'.$number["phone_number"].'" ></td><td><button class="remove_number btn btn-danger">remove</button></td></tr>';
        }
        $html .='
            <tr><td><input name="phone_types[]" type="text" ></td><td><input name="phone_numbers[]" type="text" ></td><td><button class="remove_number btn btn-danger">remove</button></td></tr>
            </table>
            <button type="button" id="add_number" class="btn btn-info" style="width: 100px; margin:20px 0px; ">add</button>
            ';
        return $html;
    }

by doing all these steps we'll get a simple table inside our add customer form ! 

please keep in mind : 

** don't use the same input field name inside the $html variable as the field name inside your grocery crud fields definition 

     example : inside $crud->fields function we pass phone_number variable and inside $html variable in the phone_number call back we use phone_numbers[]

      (different name) 

 

 

so now we should see a static table as mentioned before so now we need to bring it to live  :D  

inside your custom Javascript file put this : 

jQuery(document).ready(function(){
// Sales chart
jQuery(' #add_number').on('click', function(e){
e.preventDefault();

var row = '<tr><td><input name="phone_types[]" type="text" ></td><td><input name="phone_numbers[]" type="text" ></td><td><button class="remove_number btn btn-danger">remove</button></td></tr>';
jQuery('#phone_number tr:last').after(row);
register_remove_event();
});

function register_remove_event(){
jQuery('#phone_number button.remove_number').on('click', function (e) {
e.preventDefault();
if (jQuery('#phone_number tr').length > 2){
jQuery(this).parents('tr').remove();

}
});
}
register_remove_event();
});

the code above does nothing more than removing and adding rows in the table ! 

 

now we want to save the inserted phone numbers to the database 

easy !! 

 

use another 2 callbacks inside your class 

            $crud->callback_before_insert(array($this, 'save_phone_number'));
            $crud->callback_before_update(array($this, 'save_phone_number'));

the first one fire for new inserted customers 

the second one fires when we update an existing customer

 

they both invoke the same callback save_phone_number

 

so we need to define it  :(

    function save_phone_number($post_array, $primary_key){
        //first we delete all the old records since we're going to re-insert them back!
        $this->db->delete('phone_numbers', array('customer_id' => $primary_key));
        $i = 0;
        $data = array();
        while (!empty($post_array["phone_numbers"][$i]) ){
            $phone = array(
                'phone_type' => $post_array["phone_types"][$i],
                'phone_number' => $post_array["phone_numbers"][$i],
                'customer_id' => $primary_key
            );
            array_push($data, $phone);
            $i++;
        }
        $this->db->insert_batch('phone_numbers', $data);
    }

the code above defines the save_phone_number call back 

so what that code does is it deletes all previous phone numbers and  insert the new ones !

 

now as we can see we've finished our solution but it looks so stupid 

like miss miss colombia without makeup  :lol:

so we need to implement some styles for our new feature :D

 

so put the following code inside your css file : 

/*everything below this line is custom */
table#phone_number{
border-collapse: collapse;
width: 100%;
}
table#phone_number th, td {
text-align: left;
padding: 8px;
}
table#phone_number tr:nth-child(even){background-color: #f2f2f2}

table#phone_number th {
background-color: #46bfeb;
color: white;
}

table#phone_number th:first-child { -webkit-border-radius:5px 0 0 0; border-left:none}
table#phone_number th:last-child{ -webkit-border-radius:0 5px 0 0;border-right:none }
table#phone_number tfoot td:first-child{ -webkit-border-radius:0 0 0 5px ;}
table#phone_number tfoot td:last-child{ -webkit-border-radius:0 0 5px 0;}

table#phone_number input{
border: solid 1px lightgrey;
padding: 5px;
width: 80%;
min-width: 40px;
-webkit-border-radius: 7px;
-moz-border-radius: 5px;
border-radius: 5px;
}

and here we can see this amazing table inside our customer insertion page :D

2kjGipJ.png

 

ok guys so now we finish all this, 

anyway if I see any support or interests on this topic then I'll release a nice implementation on github which requires less code and time from you  :rolleyes:  

Kool brother - nice stuff.. 

Its worth a submission and will help quite a lot of other friends of ours.

 

Happy GCing :)




#15720 set_relation in 4 tables related to the same id? Help

Posted Amit Shah on 07 November 2017 - 05:35 PM

Well there are 2 ways to it - either you create your own model where u provide your custom query - or there is a crude way around -create number of extra columns required, make column callback - fecth the relevant values and display it.

 

Happy GCing :)




#15714 ADD, EDIT or READ without SHOW the GRID?

Posted Amit Shah on 06 November 2017 - 05:18 AM

Nice 1 Laura,

 

well .. i remember it very well in the community edition, ppl did find a hack around to deal with this situation.. but still i believe there is a way to deal with it..

If you want to bypass the grid, you can check for the state .. if the state is for listing, you can just redirect the page to wherever you want to. That way - you can still bypass the gridview.

 

Hope this solves your issue / query. 

Happy GCing :)




#15679 change text value before add_action executed

Posted Amit Shah on 24 October 2017 - 04:49 AM

well this have to do a lot with browser caching - try to expire the browser cache for the page immediately.. and that may resolve your problem.. so even though a user hits a back button .. since the cache have expired - it will pull up a fresh page from the server

 

Happy GCing :)




#15626 Themes...are we down to Bootstrap Only

Posted Amit Shah on 13 October 2017 - 07:20 PM

Well my friend, if i am not mistakened, the frontend looks more like bootstrap but it is built on react js.. not bootstrap to be precise..

And in order to make enterprise edition available for other themes like flexigrid / datatables, it will be time consumig effort .. i doubt it will be available soon for the world. As of now, the functional enahancements is what is being focused on Priority.. but yaa i believe John will also be focusing on other themes being made available.

 

Happy GCing :)




#15486 Multiselect Field Type

Posted Amit Shah on 05 September 2017 - 04:36 AM

Hi Jean,

 

Can you share the structure and the code.. i might be able to help you out on the same. I have used multi-select and am able to sort it out correctly on the order set ..

Do share the code & Structure .. and may be we could come 2 a solution