Tag Archives: DataTable

How to Solve Datatable field value is empty Error

When using datatable, the value returned by the background to the foreground will be empty. At this time, the foreground will report an error. Here are the prevention methods

$('#datatable1').DataTable( {
                ajax: {
                    "url": 'list',
                    "type": "POST",
                    data:{
                        title : function(){
                            return $("#title").val();
                        }
                    }
                },
                columnDefs: [{"defaultContent": "",
                              "targets": "_all"}],
                columns: [
                    { title: "序号", render:function(data,type,row,meta){
                        return meta.row + 1 + meta.settings._iDisplayStart }, width:"5%" },
                    { title: "推送类型", data:"mp_send_type", width:"5%" }, //x
                    { title: "推送标题", data:"mp_msg_title", width:"15%" },
                    { title: "任务ID(TASK id)", data:"mp_taskid", width:"12%" },//x */
                    { title: "推送时间", data:"mp_send_time", width:"7%" }, //x
                    { title: "推送人数", data:"mp_count", width:"5%" }, //x
                    { title: "操作人", data:"mp_admin_user_name", width:"7%" }, //    x
                    { title: "状态", render:function(data, type, row){
                        var str = "";
                        if(row.mp_status == "1"){
                            str = "<span class='label label-warning'>推送中</span>";
                        }else if(row.mp_status == "2"){
                            str = "<span class='label label-success'>推送完成</span>";
                        }else{
                            str = "<span class='label label-warning'>推送失败</span>";
                        }
                        return str;
                    } , width:"10%"}
                ]
                ,serverSide: true
                ,paging:true
                ,pagingType: "simple_numbers"
                ,lengthChange: true
                ,ordering:false
                ,info:false
                ,pageLength:10
                ,searching: false
                ,language: {
                    "url": "<%=contextPath %>/static/backend/js/Chinese.lang"
                }
            });

Intermediate:

columnDefs: [{"defaultContent": "",
                              "targets": "_all"}],

 

This means that no error will be reported when the default value is set to null

Datatable is a component of Excel which is provided by UE4 engine

Udatatable is a component provided by UE4 to read and write files. The advantage is that you don’t need to write the logic related to C + + STL API, such as fopen and Fclose, to avoid the differences between different platforms; The disadvantage is that the DataTable function you want is not implemented, so you have to use fopen to play it yourself

Reading and writing excel needs to be exported as a CSV file. At present, *. XLS format is not supported

In the following official documents, there is no specific description about the usage of defining line structure with C + + Code:

If a DataTable is created from a blueprint, then the row structure structure can also use the structure component provided by UE4. The creation method is: add new blueprints structure, and then set the row structure in this structure

If you create a DataTable with C + + code, you can directly create a new C + + class and choose to inherit the DataTable. In addition, ftablerowbase can be directly defined in the header file of the custom datatable, for example:

#pragma once

#include "Engine/DataTable.h"
#include "CharactersDT.generated.h"

USTRUCT(BlueprintType)
struct FLevelUpData : public FTableRowBase
{
	GENERATED_USTRUCT_BODY()

public:

	FLevelUpData()
		: XPtoLvl(0)
		, AdditionalHP(0)
	{}

	/** The 'Name' column is the same as the XP Level */

	/** XP to get to the given level from the previous level */
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = LevelUp)
		int32 XPtoLvl;

	/** Extra HitPoints gained at this level */
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = LevelUp)
		int32 AdditionalHP;

	/** Icon to use for Achivement */
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = LevelUp)
		TAssetPtr<UTexture> AchievementIcon;
};

Using excel to store gameplay data – DataTables

https://wiki.unrealengine.com/Using_excel_to_store_gameplay_data_-_DataTables

Data Driven Gameplay Elements

https://docs.unrealengine.com/latest/INT/Gameplay/DataDriven/index.html

Driving Gameplay with Data from Excel

https://forums.unrealengine.com/showthread.php?12572-Driving-Gameplay-with-Data-from-Excel

Methods for manipulating DataTable with blueprints.
Unreal Engine, Datatables for Blueprints (build & Use)

Excel to Unreal

https://www.youtube.com/watch?v=WLv67ddnzN0

How to load *.CSV dynamically with C++ code

If you have few tables you can use this self-contained DataTable, if you have many tables and will change them frequently, then you have to manually operate one by one in the UE editor after each change, so it is recommended to load *.csv dynamically in C++:.

FString csvFile = FPaths::GameContentDir() + "Downloads\\DownloadedFile.csv";
if (FPaths::FileExists(csvFile ))
{
	FString FileContent;
	//Read the csv file
	FFileHelper::LoadFileToString(FileContent, *csvFile );
	TArray<FString> problems = YourDataTable->CreateTableFromCSVString(FileContent);

	if (problems.Num() > 0)
	{
		for (int32 ProbIdx = 0; ProbIdx < problems.Num(); ProbIdx++)
		{        
			//Log the errors
		}
	}
	else
	{
		//Updated Successfully
	}
}