0

我正在尝试对中的所有列进行默认排序react-table v7并仅显示升序和降序,我尝试了以下

useTable(
    {
      columns,
      data,
      initialState: {
        sortBy: [
          columns.map((one) => {
            return {
              id: one.accessor ? one.accessor : one.id,
              desc: true,
            };
          }),
        ],
)

默认情况下,这确实会更改表格中的顺序,但排序图标不会出现在我这样写的列上

                 {column.isSorted ? (
                        column.isSortedDesc ? (
                          <ExpandLessIcon
                            fontSize="large"
                            style={{
                              transition: "250ms transform",
                              marginLeft: "7px",
                              fontSize: "20px",
                            }}
                            color="disabled"
                          ></ExpandLessIcon>
                        ) : (
                          <ExpandMoreIcon
                            fontSize="large"
                            style={{
                              transition: "250ms transform",
                              marginLeft: "7px",
                              fontSize: "20px",
                            }}
                            color="disabled"
                          ></ExpandMoreIcon>
                        )
                      ) : (
                        ""
                      )}

并且column.isSorted仍然是false当我控制台日志时。有人可以帮我解决这个问题吗?

4

1 回答 1

0

Array.mapreturns一个新数组,它使sortBy数组有另一个数组,它会导致问题。这有效

        sortBy: columns.map((one) => {
          return {
            desc: false,
            id: one.accessor ? one.accessor : "",
          };
        }),
于 2020-10-07T03:40:00.440 回答