|
Title: default value for column field Post by: andrux on May 09, 2013, 07:11:05 PM This one should be easy, I want to add a column to my datagrid where the field value is just a static string. I used the formatter option but it only works when you edit the grid - and I want it to always be there.
Anyone knows how to accomplish this via javascript initialization? Attached is a screenshot of what I want, it's the first column the one I want to be always the same. Thanks Title: Re: default value for column field Post by: joe on May 09, 2013, 10:18:55 PM $('#dg').datagrid({
data: [ {f1:'value11', f2:'value12'}, {f1:'value21', f2:'value22'} ] }); Title: Re: default value for column field Post by: andrux on May 10, 2013, 08:47:21 AM Thank you, Joe, but I have all my data loaded from a MySQL query, I just want the first column with a static string, and since the query is dinamically selected, I can't just put the string inside the query... actually... I might be able to...
Title: Re: default value for column field Post by: andrux on May 10, 2013, 08:56:04 AM yup,it worked... I just hope none of the queries break my little hack
I did it by doing a search and replacement in my query, like this: $query = str_replace( 'from', ', \'' . $_GET['id'] . '\' as queryId from', $options[ $_GET['id'] ]['query'] ); so that a query like "select * from wp_options" would end up like "select *, '12345' as queryId from wp_options" Thanks for the help Joe, if you come up with another way of doing it via Javascript I'd appreciate it. Title: Re: default value for column field Post by: joe on May 10, 2013, 10:26:55 AM Option 1 - pass in your string param to your SQL and push it back out as json instead of using string replace.
Option 2 - use the formatter: <th data-options="field:'Action',width:30" formatter="rowAction">my static column</th> function rowAction(){ string sMyStaticString = 'hello'; return sMyStaticString; } Title: Re: default value for column field Post by: andrux on May 10, 2013, 10:32:48 AM I don't understand what you mean for option 1
About option 2, I tried using the formatter but my static string only showed when in edit mode. Also, I'm loading via javascript Title: Re: default value for column field Post by: joe on May 10, 2013, 10:46:56 AM you are basically passing in a querying string param in your url. i.e. ...&myString=Hello, add the param to your select statement. i.e. select @myString ... and return it back to your grid.
try option 2, it should work. Title: Re: default value for column field Post by: Kevin on May 12, 2013, 07:17:16 AM I agree with Joe, option 2 (formatter) should work. Here is an example of this using jeasyui sample code. I just added the fixed column.
Code: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> Title: Re: default value for column field Post by: andrux on May 12, 2013, 09:21:27 AM I just tested and it does work, I don't know why I had problems with this before, I probably just did something wrong...
Anyway I removed my str_replace solution and I used this instead, adding the string to the $row object while fetching the record, it works just as good as the formatter options for me: Code: $response = array(); Thank you, guys |