@@ -625,6 +625,7 @@ class ModelAdmin(SqlalchemyCrud, BaseActionAdmin):
625625 page_path : str = ""
626626 bind_model : bool = True
627627 admin_action_maker : List [Callable [["ModelAdmin" ], "AdminAction" ]] = [] # Actions
628+ display_item_action_as_column : bool = False # Whether to display the item operation as a column
628629
629630 def __init__ (self , app : "AdminApp" ):
630631 assert self .model , "model is None"
@@ -693,18 +694,10 @@ async def get_list_columns(self, request: Request) -> List[TableColumn]:
693694 modelfield = self .parser .get_modelfield (field )
694695 if modelfield :
695696 columns .append (await self .get_list_column (request , modelfield ))
696- # Append operation column
697- actions = await self .get_actions (request , flag = "column" ) or []
698- for action in actions :
699- columns .append (
700- ColumnOperation (
701- fixed = "right" ,
702- label = getattr (action , "label" , _ ("Operation" )),
703- breakpoint = "*" ,
704- buttons = [action ],
705- )
706- )
707- # Append inline link model column
697+ return columns
698+
699+ async def _get_list_columns_for_link_model (self , request ) -> List [ColumnOperation ]:
700+ columns = []
708701 for link_form in self .link_model_forms :
709702 form = await link_form .get_form_item (request )
710703 if not form :
@@ -719,6 +712,23 @@ async def get_list_columns(self, request: Request) -> List[TableColumn]:
719712 )
720713 return columns
721714
715+ async def _get_list_columns_for_actions (self , request ) -> List [ColumnOperation ]:
716+ columns = []
717+ actions = await self .get_actions (request , flag = "column" ) or []
718+ action_names = {action .name for action in actions }
719+ if self .display_item_action_as_column :
720+ item_actions = await self .get_actions (request , flag = "item" ) or []
721+ actions .extend (action for action in item_actions if action .name not in action_names )
722+ if actions :
723+ columns .append (
724+ ColumnOperation (
725+ fixed = "right" ,
726+ label = _ ("Operation" ),
727+ buttons = actions ,
728+ )
729+ )
730+ return columns
731+
722732 async def get_list_table_api (self , request : Request ) -> AmisAPI :
723733 data = {"&" : "$$" }
724734 for field in self .search_fields :
@@ -754,6 +764,9 @@ async def get_list_table(self, request: Request) -> TableCRUD:
754764 },
755765 ]
756766 headerToolbar .extend (await self .get_actions (request , flag = "toolbar" ))
767+ itemActions = []
768+ if not self .display_item_action_as_column :
769+ itemActions = await self .get_actions (request , flag = "item" )
757770 table = TableCRUD (
758771 api = await self .get_list_table_api (request ),
759772 autoFillHeight = True ,
@@ -764,7 +777,7 @@ async def get_list_table(self, request: Request) -> TableCRUD:
764777 syncLocation = False ,
765778 keepItemSelectionOnPageChange = True ,
766779 perPage = self .list_per_page ,
767- itemActions = await self . get_actions ( request , flag = "item" ) ,
780+ itemActions = itemActions ,
768781 bulkActions = await self .get_actions (request , flag = "bulk" ),
769782 footerToolbar = [
770783 "statistics" ,
@@ -779,7 +792,13 @@ async def get_list_table(self, request: Request) -> TableCRUD:
779792 quickSaveItemApi = f"put:{ self .router_path } /item/${ self .pk_name } " ,
780793 defaultParams = {k : v for k , v in request .query_params .items () if v },
781794 )
782- if self .link_model_forms :
795+ # Append operation column
796+ action_columns = await self ._get_list_columns_for_actions (request )
797+ table .columns .extend (action_columns )
798+ # Append inline link model column
799+ link_model_columns = await self ._get_list_columns_for_link_model (request )
800+ if link_model_columns :
801+ table .columns .extend (link_model_columns )
783802 table .footable = True
784803 return table
785804
@@ -925,7 +944,6 @@ async def get_read_action(self, request: Request) -> Optional[Action]:
925944 return ActionType .Dialog (
926945 icon = "fa fa-eye" ,
927946 tooltip = _ ("View" ),
928- level = LevelEnum .primary ,
929947 dialog = Dialog (
930948 title = _ ("View" ) + " - " + _ (self .page_schema .label ),
931949 size = SizeEnum .lg ,
0 commit comments