PDA

View Full Version : [CLOSED] How to get the pressed value of a GridCommand ?



blueworld
Jan 07, 2013, 9:55 AM
Hello,

I have a Grid that offers a refresh button in each row. The grid also has two gridCommands with toggle functionality.

My refresh function needs to know if these gridCommands are pressed or not.

My GridCommands:




<ext:CommandColumn ID="CommandColumn2" runat="server" Width="30">
<Commands>
<ext:GridCommand Icon="ArrowSwitch" CommandName="linieAnzeigen" StandOut="false">
<ToolTip Text="Linie anzeigen" />
<CustomConfig>
<ext:ConfigItem Name="enableToggle" Value="true" />
<ext:ConfigItem Name="pressed" Value="true" />
</CustomConfig>
</ext:GridCommand>
</Commands>
<Listeners>
<Command Handler="showTourbyID(record.data.TourNummer,command);" />
</Listeners>
</ext:CommandColumn>
<ext:CommandColumn ID="CommandColumn3" runat="server" Width="30">
<Commands>
<ext:GridCommand Icon="BulletGreen" CommandName="punkteAnzeigen" StandOut="false">
<ToolTip Text="Punkte anzeigen" />
<CustomConfig>
<ext:ConfigItem Name="enableToggle" Value="true" Mode="Raw" />
</CustomConfig>
</ext:GridCommand>
</Commands>
<PrepareToolbar Fn="prepareTogglePoints" />
<Listeners>
<Command Handler="showTourbyID(record.data.TourNummer,command);" />
</Listeners>
</ext:CommandColumn>



My refresh function is client side, how can I access the pressed value(or toggle-status) of these two grid commands?

Daniil
Jan 07, 2013, 1:56 PM
Hi @blueworld,

I would try to keep pressed state of the commands in a Store's record.

blueworld
Jan 07, 2013, 2:14 PM
Hi Daniil,

so there is now way to access the pressed property directly?
Putting them into the store might be a solution, but then I have to manage these values with every toggle.

Daniil
Jan 07, 2013, 2:23 PM
You could access it this way:

App.CommandColumn1.cache[0].items.get(0);

But, I am afraid, you won't avoid using records. Because commands are re-rendered on each GridPanel refresh. For example, after any data changing: loading, sorting, filtering.

For example, if you toggle the command, then sort the data in the GridPanel, the commands will be re-rendered and the toggled state will be lost.

To avoid it, the state should be saved in a record and restored in the PrepareToolbar handler.

It was discussed here.
http://forums.ext.net/showthread.php?20770

blueworld
Jan 07, 2013, 5:15 PM
Hi Daniil,

so far your suggestion works fine except that the click event does not get triggered that way.


var prepareTogglePoints = function(grid, toolbar, rowIndex, record) {
var command = toolbar.items.get(0);
command.toggle(record.get("PunktePressed"));
};




<ext:CommandColumn ID="CommandColumn3" runat="server" Width="30">
<Commands>
<ext:GridCommand Icon="BulletGreen" CommandName="punkteAnzeigen" StandOut="false">
<ToolTip Text="Punkte anzeigen" />
<CustomConfig>
<ext:ConfigItem Name="enableToggle" Value="true" Mode="Raw" />
</CustomConfig>
</ext:GridCommand>
</Commands>
<PrepareToolbar Fn="prepareTogglePoints" />
<Listeners>
<Command Handler="showTourbyID(record.data.TourNummer,command);" />
</Listeners>
</ext:CommandColumn>


I guess its because the toolbar now just gets rendered as pressed, without having the listener active at this moment right?

Daniil
Jan 08, 2013, 9:21 AM
Seems I don't see the Click listener in your code sample. Do you mean the Command listener?

Could you, please, provide a full sample to test with?

blueworld
Jan 08, 2013, 10:59 AM
Hi Daniil,

thank you but this problem is already solved.

But I still have a problem:


App.CommandColumn1.cache[0].items.get(0);

does not return correct values if there is more than one record in my grid. If my new record is NOT pressed, this function delivers true, i guess because a previous row contains a pressed commandButton
Is there any other way to access the pressed value of my commandColumn?

Sometimes it delivers true even if ALL CommandColumns are unpressed, is there any way to force the cache to refresh ?

Daniil
Jan 08, 2013, 12:19 PM
Try to find a toolbar by record's id.


for (var i = 0, l = column.cache.length; i < l; i++) {
if (column.cache[i].record && (column.cache[i].record.id == record.id)) {
var toolbar = column.cache[i];
}
}