Web Connection
dynamically built dropdown in datagrid column
Gravatar is a globally recognized avatar based on your email address. dynamically built dropdown in datagrid column
  Doug
  All
  Mar 9, 2017 @ 02:46pm

Trying to have a datagrid column expression be a dynamically built htmldropdown, with a datasource of a dynamically built collection (oOptions), based on data in the current record.

What I'm trying to do is have the oOptions collection object be built for each record in the grid based on a value in the current record.

So I tried to have the column expression create the oOptions object like this:

loColumn.Expression = [htmldropdown("lstActions",,'oOptions = createobj('coptions',<cursor.field>)','clink','caction',,"Available Actions","")]
But am running into eval issues during the HtmlDataGrid() call.

Is there a way to have a column expression, be a dynamically blt dropdown, based on a dynamically blt collection object?

Thanks, Doug

Gravatar is a globally recognized avatar based on your email address. re: dynamically built dropdown in datagrid column
  Rick Strahl
  Doug
  Mar 9, 2017 @ 03:49pm

Please use the code formatting tools to format the code you post here... You can edit your existing post.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: dynamically built dropdown in datagrid column
  Doug
  Doug
  Mar 10, 2017 @ 10:53am

I edited the original post.

Gravatar is a globally recognized avatar based on your email address. re: dynamically built dropdown in datagrid column
  Rick Strahl
  Doug
  Mar 10, 2017 @ 02:05pm

It's usually better for more complex things to call a UDF() or method in the process class to handle the expression rather than try to debug this all inside of a string expression - the advantage is that you can set a breakpoint in the expression.

So create a method in the process class (or create UDF())):

FUNCTION GridDropDownList(lcFieldName)
LOCAL lcHTML
PRIVATE poOptions

poOptions = CREATEOBJECT(cOptions,lcFieldName)
lcHTML = htmldropdown("lstActions",,'poOptions','clink','caction',,"Available Actions","")
lcHtml = 
ENDFUNC

Then use that in the column expression:

loColumn.Expression = "Process.GridDropDownList('FieldName')"

I'm not really sure what you're doing with your expression - not sure what the lcDataSource parameter is supposed to be, but that needs to be a cursor or collection to work.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: dynamically built dropdown in datagrid column
  Doug
  Rick Strahl
  Mar 10, 2017 @ 02:42pm

That did the trick ??

The lcDatasource is poOptions. poOptions is a collection object blt dynamically based on the value of the passed in param to the createobj().

Thanks, Doug

Gravatar is a globally recognized avatar based on your email address. re: dynamically built dropdown in datagrid column
  Rick Strahl
  Doug
  Mar 10, 2017 @ 07:41pm

Great - if I have expressions of any complexity I always create a function - it's much easier to reason about the code than trying to shoehorn inside of a string expression as I almost always mess up my quotes ??

Gravatar is a globally recognized avatar based on your email address. re: dynamically built dropdown in datagrid column
  Marcel DESMET
  Rick Strahl
  Mar 11, 2017 @ 08:17am

Hy Rick, I understand your point but on the other hand subclassing could also made sommetimes things easyer. I wrap all your HTML function in a view object . And use it this way in HTML

<%=PROCESS.oView.HtmlDataGrid(PROCESS.oModel) %>

View and model could be collections ..

Just my two cents, why not a fox document object ??

PROCESS.oDoc.oGrid.oColumn etc ..

Gravatar is a globally recognized avatar based on your email address. re: dynamically built dropdown in datagrid column
  Rick Strahl
  Marcel DESMET
  Mar 11, 2017 @ 01:36pm

Sure I do the same in applications - I usually create a Model property and put all of my state and functions on that object and make that thing privcate:

<%= Model.Customer.oData.Name %>

<%= Model.Customer.CalculateOrderTotals() %>

While i think it's a good practice to do this, I also don't think it should be forced. There are many situations where you just need one or two values and there's no need to first create class - either a physical class that exists or a dynamically created EMPTY class.

If you want a more structured model for your controls etc. then you can look at the Web Control Framework, but frankly that model and the abstractions it forces are not always easier to work with.

Personally I like the MVC model because you have full control and you can pretty much accomplish a lot of what the WCF does with the HTML Helpers.

+++ Rick ---

© 1996-2017